tree-optimization/110766 - missing PHI location check

The following adds a missing PHI location check before querying
the loop latch PHI arg from it.

	PR tree-optimization/110766
	* tree-scalar-evolution.cc
	(analyze_and_compute_bitwise_induction_effect): Check the PHI
	is defined in the loop header.

	* gcc.dg/torture/pr110766.c: New testcase.
This commit is contained in:
Richard Biener 2023-07-24 08:40:19 +02:00
parent d075047259
commit fb132cdfb2
2 changed files with 18 additions and 0 deletions

View file

@ -0,0 +1,17 @@
/* { dg-do compile } */
int a, b, c, e;
short d, f;
int g(int h) { return h > a ? h : h << a; }
int main() {
while (e) {
b = 0;
for (; b < 3; b++)
if (c) {
e = g(1);
f = e | d;
}
d = 0;
}
return 0;
}

View file

@ -3519,6 +3519,7 @@ analyze_and_compute_bitwise_induction_effect (class loop* loop,
if (!gimple_bitwise_induction_p (phidef, &match_op[0], NULL)
|| TREE_CODE (match_op[2]) != SSA_NAME
|| !(header_phi = dyn_cast <gphi *> (SSA_NAME_DEF_STMT (match_op[2])))
|| gimple_bb (header_phi) != loop->header
|| gimple_phi_num_args (header_phi) != 2)
return NULL_TREE;