diff options
author | Richard Biener <rguenther@suse.de> | 2023-07-17 09:20:33 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2023-07-17 10:20:16 +0200 |
commit | b8a15313766661309698ad5cd4f000152ce74a52 (patch) | |
tree | e5bd5642298041bddc46fc569908238fe340a387 | |
parent | 95338c0d4f079a2d435f23256de321958737ebd0 (diff) | |
download | gcc-b8a15313766661309698ad5cd4f000152ce74a52.zip gcc-b8a15313766661309698ad5cd4f000152ce74a52.tar.gz gcc-b8a15313766661309698ad5cd4f000152ce74a52.tar.bz2 |
tree-optimization/110669 - bogus matching of loop bitop
The matching code lacked a check that we end up with a PHI node
in the loop header. This caused us to match a random PHI argument
now catched by the extra PHI_ARG_DEF_FROM_EDGE checking.
PR tree-optimization/110669
* tree-scalar-evolution.cc (analyze_and_compute_bitop_with_inv_effect):
Check we matched a header PHI.
* gcc.dg/torture/pr110669.c: New testcase.
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr110669.c | 15 | ||||
-rw-r--r-- | gcc/tree-scalar-evolution.cc | 1 |
2 files changed, 16 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr110669.c b/gcc/testsuite/gcc.dg/torture/pr110669.c new file mode 100644 index 0000000..b0a9ea4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr110669.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +int g_29, func_47_p_48, func_47_p_51_l_129; +void func_47_p_51() +{ + for (;;) + { + func_47_p_51_l_129 = 0; + for (; func_47_p_51_l_129 <= 1; func_47_p_51_l_129 += 1) + { + short *l_160 = (short *)(__UINTPTR_TYPE__)(func_47_p_48 || *l_160); + *l_160 &= g_29; + } + } +} diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc index 526b7f6..25e9625 100644 --- a/gcc/tree-scalar-evolution.cc +++ b/gcc/tree-scalar-evolution.cc @@ -3678,6 +3678,7 @@ analyze_and_compute_bitop_with_inv_effect (class loop* loop, tree phidef, if (TREE_CODE (match_op[1]) != SSA_NAME || !expr_invariant_in_loop_p (loop, match_op[0]) || !(header_phi = dyn_cast <gphi *> (SSA_NAME_DEF_STMT (match_op[1]))) + || gimple_bb (header_phi) != loop->header || gimple_phi_num_args (header_phi) != 2) return NULL_TREE; |