Skip to content

Commit 822c749

Browse files
committed
[LV] Shrink operands before creating new instr to force eval order.
Shrink operands before creating the new instruction to make sure the same evaluation order is used on all platforms. This fixes buildbot failures due to different argument evaluation order on different systems.
1 parent 7bd481d commit 822c749

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,21 +3595,22 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths(VPTransformState &State) {
35953595
// unfortunately.
35963596
Value *NewI = nullptr;
35973597
if (auto *BO = dyn_cast<BinaryOperator>(I)) {
3598-
NewI = B.CreateBinOp(BO->getOpcode(), ShrinkOperand(BO->getOperand(0)),
3599-
ShrinkOperand(BO->getOperand(1)));
3598+
Value *Op0 = ShrinkOperand(BO->getOperand(0));
3599+
Value *Op1 = ShrinkOperand(BO->getOperand(1));
3600+
NewI = B.CreateBinOp(BO->getOpcode(), Op0, Op1);
36003601

36013602
// Any wrapping introduced by shrinking this operation shouldn't be
36023603
// considered undefined behavior. So, we can't unconditionally copy
36033604
// arithmetic wrapping flags to NewI.
36043605
cast<BinaryOperator>(NewI)->copyIRFlags(I, /*IncludeWrapFlags=*/false);
36053606
} else if (auto *CI = dyn_cast<ICmpInst>(I)) {
3606-
NewI =
3607-
B.CreateICmp(CI->getPredicate(), ShrinkOperand(CI->getOperand(0)),
3608-
ShrinkOperand(CI->getOperand(1)));
3607+
Value *Op0 = ShrinkOperand(BO->getOperand(0));
3608+
Value *Op1 = ShrinkOperand(BO->getOperand(1));
3609+
NewI = B.CreateICmp(CI->getPredicate(), Op0, Op1);
36093610
} else if (auto *SI = dyn_cast<SelectInst>(I)) {
3610-
NewI = B.CreateSelect(SI->getCondition(),
3611-
ShrinkOperand(SI->getTrueValue()),
3612-
ShrinkOperand(SI->getFalseValue()));
3611+
Value *TV = ShrinkOperand(SI->getTrueValue());
3612+
Value *FV = ShrinkOperand(SI->getFalseValue());
3613+
NewI = B.CreateSelect(SI->getCondition(), TV, FV);
36133614
} else if (auto *CI = dyn_cast<CastInst>(I)) {
36143615
switch (CI->getOpcode()) {
36153616
default:

0 commit comments

Comments
 (0)