Skip to content

Commit 6a06155

Browse files
committed
[VectorCombine] Discard ScalarizationResults if transform aborted
Fixes #69820.
1 parent 75b3c3d commit 6a06155

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "llvm/Transforms/Vectorize/VectorCombine.h"
1616
#include "llvm/ADT/DenseMap.h"
17+
#include "llvm/ADT/ScopeExit.h"
1718
#include "llvm/ADT/Statistic.h"
1819
#include "llvm/Analysis/AssumptionCache.h"
1920
#include "llvm/Analysis/BasicAliasAnalysis.h"
@@ -1272,6 +1273,12 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
12721273
Instruction *LastCheckedInst = LI;
12731274
unsigned NumInstChecked = 0;
12741275
DenseMap<ExtractElementInst *, ScalarizationResult> NeedFreeze;
1276+
auto FailureGuard = make_scope_exit([&]() {
1277+
// If the transform is aborted, discard the ScalarizationResults.
1278+
for (auto &Pair : NeedFreeze)
1279+
Pair.second.discard();
1280+
});
1281+
12751282
// Check if all users of the load are extracts with no memory modifications
12761283
// between the load and the extract. Compute the cost of both the original
12771284
// code and the scalarized version.
@@ -1339,6 +1346,7 @@ bool VectorCombine::scalarizeLoadExtract(Instruction &I) {
13391346
replaceValue(*EI, *NewLoad);
13401347
}
13411348

1349+
FailureGuard.release();
13421350
return true;
13431351
}
13441352

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,3 +906,24 @@ exit:
906906
%p = phi i8 [ 0, %entry ], [ %ext, %then ]
907907
ret i8 0
908908
}
909+
910+
declare void @use(...)
911+
912+
; Make sure we don't assert.
913+
define void @pr69820(ptr %p, i32 %arg) {
914+
; CHECK-LABEL: @pr69820(
915+
; CHECK-NEXT: [[V:%.*]] = load <4 x float>, ptr [[P:%.*]], align 16
916+
; CHECK-NEXT: [[AND:%.*]] = and i32 [[ARG:%.*]], 3
917+
; CHECK-NEXT: [[EXT:%.*]] = extractelement <4 x float> [[V]], i32 [[AND]]
918+
; CHECK-NEXT: call void @use(<4 x float> [[V]], float [[EXT]])
919+
; CHECK-NEXT: ret void
920+
;
921+
%v = load <4 x float>, ptr %p, align 16
922+
%and = and i32 %arg, 3
923+
%ext = extractelement <4 x float> %v, i32 %and
924+
call void @use(<4 x float> %v, float %ext)
925+
ret void
926+
927+
; uselistorder directives
928+
uselistorder <4 x float> %v, { 1, 0 }
929+
}

0 commit comments

Comments
 (0)