Skip to content

Commit 93eacbc

Browse files
committed
[VectorCombine] scalarizeLoadExtract - don't create scalar loads is any extract is waiting to be erased
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
1 parent 8f4d2e0 commit 93eacbc

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
@@ -1579,6 +1579,11 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
15791579
if (!UI || UI->getParent() != LI->getParent())
15801580
return false;
15811581

1582+
// If any extract is waiting to be erased, then bail out as this will
1583+
// distort the cost calculation and possibly lead to infinite loops.
1584+
if (isInstructionTriviallyDead(UI))
1585+
return false;
1586+
15821587
// Check if any instruction between the load and the extract may modify
15831588
// memory.
15841589
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 @unsued_extract(ptr %p) {
30+
; CHECK-LABEL: @unsued_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)