Skip to content

Commit 610cc37

Browse files
committed
fixup! fixup! fixup! [VecorCombine] Avoid inserting freeze when scalarizing extend-extract if all extracts would lead to UB on poison.
1 parent 4b931b5 commit 610cc37

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,9 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
20182018
Value *ScalarV = Ext->getOperand(0);
20192019
if (!isGuaranteedNotToBePoison(ScalarV, &AC, dyn_cast<Instruction>(ScalarV),
20202020
&DT)) {
2021-
// Check if all lanes are extracted and all extracts trigger UB on poison.
2021+
// Check wether all lanes are extracted, all extracts trigger UB on
2022+
// poison, and the last extract (and hence all previous ones)
2023+
// are guaranteed to execute if Ext executes.
20222024
// If so, we do not need to insert a freeze.
20232025
SmallDenseSet<ConstantInt *, 8> ExtractedLanes;
20242026
bool AllExtractsTriggerUB = true;
@@ -2034,16 +2036,10 @@ bool VectorCombine::scalarizeExtExtract(Instruction &I) {
20342036
if (!LastExtract || LastExtract->comesBefore(Extract))
20352037
LastExtract = Extract;
20362038
}
2037-
// Check that the last extract (and hence all previous ones) are guaranteed
2038-
// to execute if Ext executes.
2039-
AllExtractsTriggerUB =
2040-
AllExtractsTriggerUB &&
2041-
all_of(make_range(Ext->getIterator(), LastExtract->getIterator()),
2042-
[](Instruction &I) {
2043-
return isGuaranteedToTransferExecutionToSuccessor(&I);
2044-
});
2045-
if (!AllExtractsTriggerUB ||
2046-
ExtractedLanes.size() != DstTy->getNumElements())
2039+
if (ExtractedLanes.size() != DstTy->getNumElements() ||
2040+
!AllExtractsTriggerUB ||
2041+
!isGuaranteedToTransferExecutionToSuccessor(Ext->getIterator(),
2042+
LastExtract->getIterator()))
20472043
ScalarV = Builder.CreateFreeze(ScalarV);
20482044
}
20492045
ScalarV = Builder.CreateBitCast(

0 commit comments

Comments
 (0)