Skip to content

Commit

Permalink
[VectorCombine] scalarizeLoadExtract - don't create scalar loads is a…
Browse files Browse the repository at this point in the history
…ny 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
  • Loading branch information
RKSimon committed Mar 1, 2025
1 parent 8f4d2e0 commit 93eacbc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/Vectorize/VectorCombine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,11 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
if (!UI || UI->getParent() != LI->getParent())
return false;

// If any extract is waiting to be erased, then bail out as this will
// distort the cost calculation and possibly lead to infinite loops.
if (isInstructionTriviallyDead(UI))
return false;

// Check if any instruction between the load and the extract may modify
// memory.
if (LastCheckedInst->comesBefore(UI)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ define void @multiple_extract(ptr %p) {
store i32 %e1, ptr %p1, align 4
ret void
}

; infinite loop if we fold an extract that is waiting to be erased
define void @unsued_extract(ptr %p) {
; CHECK-LABEL: @unsued_extract(
; CHECK-NEXT: ret void
;
%load = load <4 x float>, ptr %p, align 8
%shuffle0 = shufflevector <4 x float> zeroinitializer, <4 x float> %load, <4 x i32> <i32 0, i32 4, i32 1, i32 5>
%shuffle1 = shufflevector <4 x float> %shuffle0, <4 x float> zeroinitializer, <4 x i32> <i32 0, i32 4, i32 poison, i32 poison>
%extract = extractelement <4 x float> %load, i64 1
ret void
}

0 comments on commit 93eacbc

Please sign in to comment.