[llvm] bd8fe99 - [VPlan] Mov licm to end of VPlan optimizations.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 21 04:46:17 PDT 2024


Author: Florian Hahn
Date: 2024-09-21T12:45:45+01:00
New Revision: bd8fe9972e3f17776e4e05e69e13ab8271d34132

URL: https://github.com/llvm/llvm-project/commit/bd8fe9972e3f17776e4e05e69e13ab8271d34132
DIFF: https://github.com/llvm/llvm-project/commit/bd8fe9972e3f17776e4e05e69e13ab8271d34132.diff

LOG: [VPlan] Mov licm to end of VPlan optimizations.

This moves licm after expanding replicate regions. This fixes a crash
when trying to hoist a predicated VPReplicateRecipes which later get
expanded to replicate regions.

Hoisting replicate regions out was not intended (see the discussion and
at the review and comment on shallow traversal in licm()).

Fixes https://github.com/llvm/llvm-project/issues/109510.

Added: 
    llvm/test/Transforms/LoopVectorize/invariant-replicate-region.ll

Modified: 
    llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
index 06ac15f52fe137..fd6090affbbf18 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
@@ -1158,7 +1158,6 @@ void VPlanTransforms::optimize(VPlan &Plan) {
   removeRedundantInductionCasts(Plan);
 
   simplifyRecipes(Plan);
-  licm(Plan);
   legalizeAndOptimizeInductions(Plan);
   removeDeadRecipes(Plan);
 
@@ -1166,6 +1165,7 @@ void VPlanTransforms::optimize(VPlan &Plan) {
 
   removeRedundantExpandSCEVRecipes(Plan);
   mergeBlocksIntoPredecessors(Plan);
+  licm(Plan);
 }
 
 // Add a VPActiveLaneMaskPHIRecipe and related recipes to \p Plan and replace

diff  --git a/llvm/test/Transforms/LoopVectorize/invariant-replicate-region.ll b/llvm/test/Transforms/LoopVectorize/invariant-replicate-region.ll
new file mode 100644
index 00000000000000..34980aa2c378a6
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/invariant-replicate-region.ll
@@ -0,0 +1,27 @@
+; RUN: opt -p loop-vectorize -force-vector-width=4 -S %s | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
+target triple = "arm64-apple-macosx14.0.0"
+
+; Test for https://github.com/llvm/llvm-project/issues/109510.
+define i32 @test_invariant_replicate_region(i32 %x, i1 %c) {
+entry:
+  br label %loop.header
+
+loop.header:
+  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
+  br i1 %c, label %then, label %loop.latch
+
+then:
+  %rem.1 = urem i32 10, %x
+  br label %loop.latch
+
+loop.latch:
+  %res = phi i32 [ 0, %loop.header ], [ %rem.1, %then ]
+  %iv.next = add i32 %iv, 1
+  %ec = icmp eq i32 %iv, 99
+  br i1 %ec, label %exit, label %loop.header
+
+exit:
+  ret i32 %res
+}


        


More information about the llvm-commits mailing list