diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-06-21 14:59:35 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-06-21 14:59:35 +0000 |
commit | 3e5c051a06d42df95fdf76d96a01e5c09fa05a6c (patch) | |
tree | 925d759f3b172f3dce5bd919b8adcf293228e9e3 /llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | |
parent | ad71333b92a9ad31fd3b7a3fd2264b9ab9c1455f (diff) | |
download | bcm5719-llvm-3e5c051a06d42df95fdf76d96a01e5c09fa05a6c.tar.gz bcm5719-llvm-3e5c051a06d42df95fdf76d96a01e5c09fa05a6c.zip |
[InstCombine] make div/rem vector constant utility function; NFCI
This was originally in D48401 and will be used there.
llvm-svn: 335242
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstructionCombining.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 1281c99f8dd..84535f971b5 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1417,23 +1417,17 @@ 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. - // 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). - if (Inst.isIntDivRem()) { - 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); - } - + // 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). + if (Inst.isIntDivRem()) + NewC = getSafeVectorConstantForIntDivRem(NewC); + // Op(shuffle(V1, Mask), C) -> shuffle(Op(V1, NewC), Mask) // Op(C, shuffle(V1, Mask)) -> shuffle(Op(NewC, V1), Mask) - Constant *NewC = ConstantVector::get(NewVecC); Value *NewLHS = isa<Constant>(LHS) ? NewC : V1; Value *NewRHS = isa<Constant>(LHS) ? V1 : NewC; return createBinOpShuffle(NewLHS, NewRHS, Mask); |