Skip to content

Commit bd8fe99

Browse files
committed
[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 #109510.
1 parent eb6e7e8 commit bd8fe99

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,14 +1158,14 @@ void VPlanTransforms::optimize(VPlan &Plan) {
11581158
removeRedundantInductionCasts(Plan);
11591159

11601160
simplifyRecipes(Plan);
1161-
licm(Plan);
11621161
legalizeAndOptimizeInductions(Plan);
11631162
removeDeadRecipes(Plan);
11641163

11651164
createAndOptimizeReplicateRegions(Plan);
11661165

11671166
removeRedundantExpandSCEVRecipes(Plan);
11681167
mergeBlocksIntoPredecessors(Plan);
1168+
licm(Plan);
11691169
}
11701170

11711171
// Add a VPActiveLaneMaskPHIRecipe and related recipes to \p Plan and replace
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: opt -p loop-vectorize -force-vector-width=4 -S %s | FileCheck %s
2+
3+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128-Fn32"
4+
target triple = "arm64-apple-macosx14.0.0"
5+
6+
; Test for https://github.com/llvm/llvm-project/issues/109510.
7+
define i32 @test_invariant_replicate_region(i32 %x, i1 %c) {
8+
entry:
9+
br label %loop.header
10+
11+
loop.header:
12+
%iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.latch ]
13+
br i1 %c, label %then, label %loop.latch
14+
15+
then:
16+
%rem.1 = urem i32 10, %x
17+
br label %loop.latch
18+
19+
loop.latch:
20+
%res = phi i32 [ 0, %loop.header ], [ %rem.1, %then ]
21+
%iv.next = add i32 %iv, 1
22+
%ec = icmp eq i32 %iv, 99
23+
br i1 %ec, label %exit, label %loop.header
24+
25+
exit:
26+
ret i32 %res
27+
}

0 commit comments

Comments
 (0)