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>
--- /dev/null
+/* 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;
+}
--- /dev/null
+/* 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" } } */