]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Swap loop splitting and final value replacement
authorRichard Biener <rguenther@suse.de>
Thu, 3 Aug 2023 08:59:52 +0000 (10:59 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 3 Aug 2023 11:20:00 +0000 (13:20 +0200)
The following swaps the loop splitting pass and the final value
replacement pass to avoid keeping the IV of the earlier loop
live when not necessary.  The existing gcc.target/i386/pr87007-5.c
testcase shows that we otherwise fail to elide an empty loop
later.  I don't see any good reason why loop splitting would need
final value replacement, all exit values honor the constraints
we place on loop header PHIs automatically.

* passes.def: Exchange loop splitting and final value
replacement passes.

* gcc.target/i386/pr87007-5.c: Make sure we split the loop
and eliminate both in the end.

gcc/passes.def
gcc/testsuite/gcc.target/i386/pr87007-5.c

index f2893ae8a8b2dd3b272131660fc7fd07f6c734fb..ef5a21afe497d5cc34e54e5178504b9f06ea52c2 100644 (file)
@@ -282,8 +282,8 @@ along with GCC; see the file COPYING3.  If not see
             form if possible.  */
          NEXT_PASS (pass_tree_loop_init);
          NEXT_PASS (pass_tree_unswitch);
-         NEXT_PASS (pass_scev_cprop);
          NEXT_PASS (pass_loop_split);
+         NEXT_PASS (pass_scev_cprop);
          NEXT_PASS (pass_loop_versioning);
          NEXT_PASS (pass_loop_jam);
          /* All unswitching, final value replacement and splitting can expose
index b36e81c270c937559ecd6aebaa4973a2174581d8..a6cdf11522e579f0298f6c81c58c30e8b0c1d9a9 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-Ofast -march=skylake-avx512 -mfpmath=sse -fno-tree-vectorize" } */
+/* { dg-options "-Ofast -march=skylake-avx512 -mfpmath=sse -fno-tree-vectorize -fdump-tree-cddce3-details -fdump-tree-lsplit-optimized" } */
 /* Load of d2/d3 is hoisted out, vrndscalesd will reuse loades register to avoid partial dependence.  */
 
 #include<math.h>
@@ -15,4 +15,6 @@ foo (int n, int k)
       d1 = sqrt (d3);
 }
 
+/* { dg-final { scan-tree-dump "optimized: loop split" "lsplit" } } */
+/* { dg-final { scan-tree-dump-times "removing loop" 2 "cddce3" } } */
 /* { dg-final { scan-assembler-times "vxorps\[^\n\r\]*xmm\[0-9\]" 0 } } */