[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.
This commit is contained in:
Florian Hahn 2023-07-30 17:15:09 +01:00
parent 7bd481d9af
commit 822c749aec
No known key found for this signature in database
GPG Key ID: 9E54DEA47A8F4434

View File

@ -3595,21 +3595,22 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths(VPTransformState &State) {
// unfortunately.
Value *NewI = nullptr;
if (auto *BO = dyn_cast<BinaryOperator>(I)) {
NewI = B.CreateBinOp(BO->getOpcode(), ShrinkOperand(BO->getOperand(0)),
ShrinkOperand(BO->getOperand(1)));
Value *Op0 = ShrinkOperand(BO->getOperand(0));
Value *Op1 = ShrinkOperand(BO->getOperand(1));
NewI = B.CreateBinOp(BO->getOpcode(), Op0, Op1);
// Any wrapping introduced by shrinking this operation shouldn't be
// considered undefined behavior. So, we can't unconditionally copy
// arithmetic wrapping flags to NewI.
cast<BinaryOperator>(NewI)->copyIRFlags(I, /*IncludeWrapFlags=*/false);
} else if (auto *CI = dyn_cast<ICmpInst>(I)) {
NewI =
B.CreateICmp(CI->getPredicate(), ShrinkOperand(CI->getOperand(0)),
ShrinkOperand(CI->getOperand(1)));
Value *Op0 = ShrinkOperand(BO->getOperand(0));
Value *Op1 = ShrinkOperand(BO->getOperand(1));
NewI = B.CreateICmp(CI->getPredicate(), Op0, Op1);
} else if (auto *SI = dyn_cast<SelectInst>(I)) {
NewI = B.CreateSelect(SI->getCondition(),
ShrinkOperand(SI->getTrueValue()),
ShrinkOperand(SI->getFalseValue()));
Value *TV = ShrinkOperand(SI->getTrueValue());
Value *FV = ShrinkOperand(SI->getFalseValue());
NewI = B.CreateSelect(SI->getCondition(), TV, FV);
} else if (auto *CI = dyn_cast<CastInst>(I)) {
switch (CI->getOpcode()) {
default: