Skip to content

Commit 548d057

Browse files
RKSimontstellar
authored andcommitted
[VectorCombine] scalarizeLoadExtract - don't create scalar loads if any extract is waiting to be erased (#129375)
If any extract is waiting to be erased, then bail out as this will distort the cost calculation and possibly lead to infinite loops. Fixes #129373 (cherry picked from commit 5ddf40f)
1 parent 7c154da commit 548d057

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,11 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
14031403
if (!UI || UI->getParent() != LI->getParent())
14041404
return false;
14051405

1406+
// If any extract is waiting to be erased, then bail out as this will
1407+
// distort the cost calculation and possibly lead to infinite loops.
1408+
if (UI->use_empty())
1409+
return false;
1410+
14061411
// Check if any instruction between the load and the extract may modify
14071412
// memory.
14081413
if (LastCheckedInst->comesBefore(UI)) {

llvm/test/Transforms/VectorCombine/X86/load-extractelement-scalarization.ll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ define void @multiple_extract(ptr %p) {
2424
store i32 %e1, ptr %p1, align 4
2525
ret void
2626
}
27+
28+
; infinite loop if we fold an extract that is waiting to be erased
29+
define void @unused_extract(ptr %p) {
30+
; CHECK-LABEL: @unused_extract(
31+
; CHECK-NEXT: ret void
32+
;
33+
%load = load <4 x float>, ptr %p, align 8
34+
%shuffle0 = shufflevector <4 x float> zeroinitializer, <4 x float> %load, <4 x i32> <i32 0, i32 4, i32 1, i32 5>
35+
%shuffle1 = shufflevector <4 x float> %shuffle0, <4 x float> zeroinitializer, <4 x i32> <i32 0, i32 4, i32 poison, i32 poison>
36+
%extract = extractelement <4 x float> %load, i64 1
37+
ret void
38+
}

0 commit comments

Comments
 (0)