summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index f87b94dd355..2b9db4baafa 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1417,21 +1417,21 @@ Instruction *InstCombiner::foldShuffledBinop(BinaryOperator &Inst) {
}
}
if (MayChange) {
- // It's not safe to use a vector with undef elements because the entire
- // instruction can be folded to undef (for example, div/rem divisors).
- // Replace undef lanes with the first non-undef element. Vector demanded
- // elements can change those back to undef values if that is safe.
- Constant *SafeDummyConstant = nullptr;
- for (unsigned i = 0; i < VWidth; ++i) {
- if (!isa<UndefValue>(NewVecC[i])) {
- SafeDummyConstant = NewVecC[i];
- break;
- }
+ // With integer div/rem instructions, it is not safe to use a vector with
+ // undef elements because the entire instruction can be folded to undef.
+ // So replace undef elements with '1' because that can never induce
+ // undefined behavior. All other binop opcodes are always safe to
+ // speculate, and therefore, it is fine to include undef elements for
+ // unused lanes (and using undefs may help optimization).
+ BinaryOperator::BinaryOps Opcode = Inst.getOpcode();
+ if (Opcode == Instruction::UDiv || Opcode == Instruction::URem ||
+ Opcode == Instruction::SDiv || Opcode == Instruction::SRem) {
+ assert(C->getType()->getScalarType()->isIntegerTy() &&
+ "Not expecting FP opcodes/operands/constants here");
+ for (unsigned i = 0; i < VWidth; ++i)
+ if (isa<UndefValue>(NewVecC[i]))
+ NewVecC[i] = ConstantInt::get(NewVecC[i]->getType(), 1);
}
- assert(SafeDummyConstant && "Undef constant vector was not simplified?");
- for (unsigned i = 0; i < VWidth; ++i)
- if (isa<UndefValue>(NewVecC[i]))
- NewVecC[i] = SafeDummyConstant;
// Op(shuffle(V1, Mask), C) -> shuffle(Op(V1, NewC), Mask)
// Op(C, shuffle(V1, Mask)) -> shuffle(Op(NewC, V1), Mask)
OpenPOWER on IntegriCloud