]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
testsuite: Add regression test for PR81549
authorNaveen <naveen.siddegowda@oss.qualcomm.com>
Fri, 17 Jul 2026 11:13:10 +0000 (04:13 -0700)
committerNaveen <naveen.siddegowda@oss.qualcomm.com>
Fri, 17 Jul 2026 11:13:10 +0000 (04:13 -0700)
The testcase from PR tree-optimization/81549 is already optimized on
current trunk by the existing loop-PHI final-value replacement code.
Add the testcase to preserve coverage for the delayed loop-carried value
and verify that the final stores and return value are folded to constants.

gcc/testsuite/ChangeLog:

PR tree-optimization/81549
* gcc.dg/tree-ssa/pr81549.c: New test.
* gcc.dg/tree-ssa/pr81549-2.c: New test.

Signed-off-by: Naveen <naveen.siddegowda@oss.qualcomm.com>
gcc/testsuite/gcc.dg/tree-ssa/pr81549-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr81549.c [new file with mode: 0644]

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr81549-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr81549-2.c
new file mode 100644 (file)
index 0000000..236ef0c
--- /dev/null
@@ -0,0 +1,46 @@
+/* PR tree-optimization/81549 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+int a[4];
+
+__attribute__((noipa)) int
+f (int n)
+{
+  int t0 = a[0];
+  int t1 = a[1];
+
+  for (int i = 0; i < n; ++i)
+    {
+      t0 = t1;
+      t1 = 2;
+    }
+
+  return t0;
+}
+
+__attribute__((noipa)) int
+g (void)
+{
+  int t0 = a[0];
+  int t1 = a[1];
+
+  for (int i = 0; i < 1; ++i)
+    {
+      t0 = t1;
+      t1 = 2;
+    }
+
+  return t0;
+}
+
+int
+main (void)
+{
+  a[0] = 11;
+  a[1] = 22;
+
+  if (f (0) != 11 || f (1) != 22 || f (2) != 2 || g () != 22)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr81549.c b/gcc/testsuite/gcc.dg/tree-ssa/pr81549.c
new file mode 100644 (file)
index 0000000..fdbe79a
--- /dev/null
@@ -0,0 +1,28 @@
+/* PR tree-optimization/81549 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-sccp-details -fdump-tree-optimized" } */
+
+int a[10000];
+
+int
+f (void)
+{
+  int t0 = a[0];
+  int t1 = a[1];
+
+  for (int i = 0; i < 100; ++i)
+    {
+      a[i] = 1;
+      t0 = t1;
+      t1 = 2;
+    }
+
+  a[100] = t0;
+  a[101] = t1;
+  return t0 + t1;
+}
+
+/* { dg-final { scan-tree-dump-times "with expr: 2" 1 "sccp" } } */
+/* { dg-final { scan-tree-dump {a\[100\] = 2;} "sccp" } } */
+/* { dg-final { scan-tree-dump {a\[101\] = 2;} "sccp" } } */
+/* { dg-final { scan-tree-dump "return 4;" "optimized" } } */