[llvm] 5d7afe2 - [Scalarizer] visit{Insert,Extract}ElementInst(): avoid call arg evaluation order deps
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 6 03:42:57 PDT 2020
Author: Roman Lebedev
Date: 2020-07-06T13:42:35+03:00
New Revision: 5d7afe2d2e3c1a4715d022bfdb0c35df153e5430
URL: https://github.com/llvm/llvm-project/commit/5d7afe2d2e3c1a4715d022bfdb0c35df153e5430
DIFF: https://github.com/llvm/llvm-project/commit/5d7afe2d2e3c1a4715d022bfdb0c35df153e5430.diff
LOG: [Scalarizer] visit{Insert,Extract}ElementInst(): avoid call arg evaluation order deps
Compilers may evaluate call arguments in different order,
which would result in different order of IR, which would break the tests.
Spotted thanks to Dmitri Gribenko!
Added:
Modified:
llvm/lib/Transforms/Scalar/Scalarizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp b/llvm/lib/Transforms/Scalar/Scalarizer.cpp
index a775be6ef7b8..5cac4dca8cf8 100644
--- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp
+++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp
@@ -769,10 +769,12 @@ bool ScalarizerVisitor::visitInsertElementInst(InsertElementInst &IEI) {
return false;
for (unsigned I = 0; I < NumElems; ++I) {
- Res[I] = Builder.CreateSelect(
+ Value *ShouldReplace =
Builder.CreateICmpEQ(InsIdx, ConstantInt::get(InsIdx->getType(), I),
- InsIdx->getName() + ".is." + Twine(I)),
- NewElt, Op0[I], IEI.getName() + ".i" + Twine(I));
+ InsIdx->getName() + ".is." + Twine(I));
+ Value *OldElt = Op0[I];
+ Res[I] = Builder.CreateSelect(ShouldReplace, NewElt, OldElt,
+ IEI.getName() + ".i" + Twine(I));
}
}
@@ -801,10 +803,12 @@ bool ScalarizerVisitor::visitExtractElementInst(ExtractElementInst &EEI) {
Value *Res = UndefValue::get(VT->getElementType());
for (unsigned I = 0; I < NumSrcElems; ++I) {
- Res = Builder.CreateSelect(
+ Value *ShouldExtract =
Builder.CreateICmpEQ(ExtIdx, ConstantInt::get(ExtIdx->getType(), I),
- ExtIdx->getName() + ".is." + Twine(I)),
- Op0[I], Res, EEI.getName() + ".upto" + Twine(I));
+ ExtIdx->getName() + ".is." + Twine(I));
+ Value *Elt = Op0[I];
+ Res = Builder.CreateSelect(ShouldExtract, Elt, Res,
+ EEI.getName() + ".upto" + Twine(I));
}
gather(&EEI, {Res});
return true;
More information about the llvm-commits
mailing list