aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2023-07-24 08:40:19 +0200
committerRichard Biener <rguenther@suse.de>2023-07-24 09:50:32 +0200
commitfb132cdfb204bc12851eb1d5852eef6f03c13af3 (patch)
treef3c37b9802a26c6799bba539e763215e0c763c48 /gcc
parentd07504725973ccdec78929a09dc13e5ebd9472f6 (diff)
downloadgcc-fb132cdfb204bc12851eb1d5852eef6f03c13af3.zip
gcc-fb132cdfb204bc12851eb1d5852eef6f03c13af3.tar.gz
gcc-fb132cdfb204bc12851eb1d5852eef6f03c13af3.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr110766.c17
-rw-r--r--gcc/tree-scalar-evolution.cc1
2 files changed, 18 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/torture/pr110766.c b/gcc/testsuite/gcc.dg/torture/pr110766.c
new file mode 100644
index 0000000..97dcacf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr110766.c
@@ -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;
+}
diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
index 2abe8fa..3fb6951 100644
--- a/gcc/tree-scalar-evolution.cc
+++ b/gcc/tree-scalar-evolution.cc
@@ -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;