From: Naveen Date: Fri, 17 Jul 2026 11:13:10 +0000 (-0700) Subject: testsuite: Add regression test for PR81549 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bbc7fd5ae68069863b77a9d614a9aa82a4079e58;p=thirdparty%2Fgcc.git testsuite: Add regression test for PR81549 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 --- 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 index 00000000000..236ef0cabd0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr81549-2.c @@ -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 index 00000000000..fdbe79ab1c5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr81549.c @@ -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" } } */