summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-07-09 16:16:51 +0000
committerSanjay Patel <spatel@rotateright.com>2018-07-09 16:16:51 +0000
commita62725317bd1135d90bd0400e3f43441cc56ad4f (patch)
tree10b1a32bb4b5487ad4f24da0833268cfacfb4d61 /llvm/lib/Transforms/InstCombine/InstCombineInternal.h
parente9cff7d47b862fa992169caeba7255ceb74c5362 (diff)
downloadbcm5719-llvm-a62725317bd1135d90bd0400e3f43441cc56ad4f.tar.gz
bcm5719-llvm-a62725317bd1135d90bd0400e3f43441cc56ad4f.zip
[InstCombine] generalize safe vector constant utility
This is almost NFC, but there could be some case where the original code had undefs in the constants (rather than just the shuffle mask), and we'll use safe constants rather than undefs now. The FIXME noted in foldShuffledBinop() is already visible in existing tests, so correcting that is the next step. llvm-svn: 336558
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineInternal.h')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineInternal.h25
1 files changed, 16 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 75fec3e79d3..452079354e4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -212,19 +212,26 @@ IntrinsicIDToOverflowCheckFlavor(unsigned ID) {
}
}
-/// Integer division/remainder require special handling to avoid undefined
+/// Some binary operators require special handling to avoid poison and undefined
/// behavior. If a constant vector has undef elements, replace those undefs with
-/// '1' because that's always safe to execute.
-static inline Constant *getSafeVectorConstantForIntDivRem(Constant *In) {
- assert(In->getType()->isVectorTy() && "Not expecting scalars here");
- assert(In->getType()->getVectorElementType()->isIntegerTy() &&
- "Not expecting FP opcodes/operands/constants here");
-
- unsigned NumElts = In->getType()->getVectorNumElements();
+/// identity constants because those are always safe to execute. If no identity
+/// constant exists, replace undef with '1' or '1.0'.
+static inline Constant *getSafeVectorConstantForBinop(
+ BinaryOperator::BinaryOps Opcode, Constant *In) {
+ Type *Ty = In->getType();
+ assert(Ty->isVectorTy() && "Not expecting scalars here");
+
+ Type *EltTy = Ty->getVectorElementType();
+ Constant *IdentityC = ConstantExpr::getBinOpIdentity(Opcode, EltTy, true);
+ if (!IdentityC)
+ IdentityC = EltTy->isIntegerTy() ? ConstantInt::get(EltTy, 1):
+ ConstantFP::get(EltTy, 1.0);
+
+ unsigned NumElts = Ty->getVectorNumElements();
SmallVector<Constant *, 16> Out(NumElts);
for (unsigned i = 0; i != NumElts; ++i) {
Constant *C = In->getAggregateElement(i);
- Out[i] = isa<UndefValue>(C) ? ConstantInt::get(C->getType(), 1) : C;
+ Out[i] = isa<UndefValue>(C) ? IdentityC : C;
}
return ConstantVector::get(Out);
}
OpenPOWER on IntegriCloud