aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2024-05-23 14:36:39 +0200
committerRichard Biener <rguenther@suse.de>2024-05-29 08:29:25 +0200
commit2a1fdd5fd0f6bc02d25da192c8fa6487d93d2d50 (patch)
tree3e20419ffad60dbd2434f99fad5e2b313bd597f0
parent9e971c671ded9647beb0a1c5b9430b4e64060862 (diff)
downloadgcc-2a1fdd5fd0f6bc02d25da192c8fa6487d93d2d50.zip
gcc-2a1fdd5fd0f6bc02d25da192c8fa6487d93d2d50.tar.gz
gcc-2a1fdd5fd0f6bc02d25da192c8fa6487d93d2d50.tar.bz2
tree-optimization/115197 - fix ICE w/ constant in LC PHI and loop distribution
Forgot a check for an SSA name before trying to replace a PHI arg with its current definition. PR tree-optimization/115197 * tree-loop-distribution.cc (copy_loop_before): Constant PHI args remain the same. * gcc.dg/pr115197.c: New testcase. (cherry picked from commit 2b2476d4d18c92b8aba3567ebccd2100c2f7c258)
-rw-r--r--gcc/testsuite/gcc.dg/pr115197.c14
-rw-r--r--gcc/tree-loop-distribution.cc7
2 files changed, 19 insertions, 2 deletions
diff --git a/gcc/testsuite/gcc.dg/pr115197.c b/gcc/testsuite/gcc.dg/pr115197.c
new file mode 100644
index 0000000..00d674b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr115197.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fno-tree-scev-cprop -ftree-pre -ftree-loop-distribute-patterns" } */
+
+int a, b[2], c, d, e, f[2];
+int main() {
+ while (a)
+ if (d) {
+ if (e)
+ return 0;
+ for (; c; c++)
+ f[c] = 0 < (b[c] = ~(f[c + 1] < a));
+ }
+ return 0;
+}
diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc
index 45932ba..c5a05ee 100644
--- a/gcc/tree-loop-distribution.cc
+++ b/gcc/tree-loop-distribution.cc
@@ -977,8 +977,11 @@ copy_loop_before (class loop *loop, bool redirect_lc_phi_defs)
if (virtual_operand_p (gimple_phi_result (phi)))
continue;
use_operand_p use_p = PHI_ARG_DEF_PTR_FROM_EDGE (phi, exit);
- tree new_def = get_current_def (USE_FROM_PTR (use_p));
- SET_USE (use_p, new_def);
+ if (TREE_CODE (USE_FROM_PTR (use_p)) == SSA_NAME)
+ {
+ tree new_def = get_current_def (USE_FROM_PTR (use_p));
+ SET_USE (use_p, new_def);
+ }
}
}