summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2018-10-10 20:39:39 +0000
committerSanjay Patel <spatel@rotateright.com>2018-10-10 20:39:39 +0000
commit58fc00d0bc1d33afbecfd7d83fb60529b7decb40 (patch)
tree92a2fbc71110c479f94444f2951e915f238a5c00 /llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
parent9ae88c64fa6ee582578c4a018cf92ada6a8bb08d (diff)
downloadbcm5719-llvm-58fc00d0bc1d33afbecfd7d83fb60529b7decb40.tar.gz
bcm5719-llvm-58fc00d0bc1d33afbecfd7d83fb60529b7decb40.zip
revert r344082: [InstCombine] reverse 'trunc X to <N x i1>' canonicalization
This commit accidentally included the diffs from D53057. llvm-svn: 344178
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp31
1 files changed, 4 insertions, 27 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 74f1e695ff6..fd59c3a7c0c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -706,35 +706,12 @@ Instruction *InstCombiner::visitTrunc(TruncInst &CI) {
if (SimplifyDemandedInstructionBits(CI))
return &CI;
+ // Canonicalize trunc x to i1 -> (icmp ne (and x, 1), 0), likewise for vector.
if (DestTy->getScalarSizeInBits() == 1) {
+ Constant *One = ConstantInt::get(SrcTy, 1);
+ Src = Builder.CreateAnd(Src, One);
Value *Zero = Constant::getNullValue(Src->getType());
- if (DestTy->isIntegerTy()) {
- // Canonicalize trunc x to i1 -> icmp ne (and x, 1), 0 (scalar only).
- // TODO: We canonicalize to more instructions here because we are probably
- // lacking equivalent analysis for trunc relative to icmp. There may also
- // be codegen concerns. If those trunc limitations were removed, we could
- // remove this transform.
- Value *And = Builder.CreateAnd(Src, ConstantInt::get(SrcTy, 1));
- return new ICmpInst(ICmpInst::ICMP_NE, And, Zero);
- }
-
- // For vectors, we do not canonicalize all truncs to icmp, so optimize
- // patterns that would be covered within visitICmpInst.
- Value *X;
- const APInt *C;
- if (match(Src, m_OneUse(m_LShr(m_Value(X), m_APInt(C))))) {
- // trunc (lshr X, C) to i1 --> icmp ne (and X, C'), 0
- APInt MaskC = APInt(SrcTy->getScalarSizeInBits(), 1).shl(*C);
- Value *And = Builder.CreateAnd(X, ConstantInt::get(SrcTy, MaskC));
- return new ICmpInst(ICmpInst::ICMP_NE, And, Zero);
- }
- if (match(Src, m_OneUse(m_c_Or(m_LShr(m_Value(X), m_APInt(C)),
- m_Deferred(X))))) {
- // trunc (or (lshr X, C), X) to i1 --> icmp ne (and X, C'), 0
- APInt MaskC = APInt(SrcTy->getScalarSizeInBits(), 1).shl(*C) | 1;
- Value *And = Builder.CreateAnd(X, ConstantInt::get(SrcTy, MaskC));
- return new ICmpInst(ICmpInst::ICMP_NE, And, Zero);
- }
+ return new ICmpInst(ICmpInst::ICMP_NE, Src, Zero);
}
// FIXME: Maybe combine the next two transforms to handle the no cast case
OpenPOWER on IntegriCloud