summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-07-09 17:20:20 +0000
committerSanjay Patel <spatel@rotateright.com>2018-07-09 17:20:20 +0000
commit7cd32419ab0ac5ff9609fcff12657b1ac6554e76 (patch)
tree56d090e39bf7627154375a53a7f308c09195c41f /llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
parent82dee6aca8755abb3cd2383ce9b46db722d52b21 (diff)
downloadbcm5719-llvm-7cd32419ab0ac5ff9609fcff12657b1ac6554e76.tar.gz
bcm5719-llvm-7cd32419ab0ac5ff9609fcff12657b1ac6554e76.zip
[InstCombine] avoid extra poison when moving shift above shuffle
As discussed in D49047 / D48987, shift-by-undef produces poison, so we can't use undef vector elements in that case.. Note that we need to extend this for poison-generating flags, and there's a proposal to create poison from FMF in D47963, llvm-svn: 336562
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp13
1 files changed, 5 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index c28c5138dab..5f0aeb5cc5a 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1418,14 +1418,11 @@ Instruction *InstCombiner::foldShuffledBinop(BinaryOperator &Inst) {
}
if (MayChange) {
Constant *NewC = ConstantVector::get(NewVecC);
- // 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.
- // 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).
- // FIXME: This transform is also not poison-safe. Eg, shift-by-undef would
- // create poison that may not exist in the original code.
- if (Inst.isIntDivRem())
+ // It may not be safe to execute a binop on a vector with undef elements
+ // because the entire instruction can be folded to undef or create poison
+ // that did not exist in the original code.
+ if (Inst.isIntDivRem() ||
+ (Inst.isShift() && isa<Constant>(Inst.getOperand(1))))
NewC = getSafeVectorConstantForBinop(Inst.getOpcode(), NewC);
// Op(shuffle(V1, Mask), C) -> shuffle(Op(V1, NewC), Mask)
OpenPOWER on IntegriCloud