diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-07-23 13:06:49 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-07-23 13:06:49 +0000 |
commit | 1271bf91783cdb0bebd701dea98907b1fbee68e5 (patch) | |
tree | 5b18f4d667eaef6291c9c3b58242c2ff1dcfecf5 /llvm/lib/Transforms | |
parent | 488cb137a98201afc20a29a389a61f87bda69020 (diff) | |
download | bcm5719-llvm-1271bf91783cdb0bebd701dea98907b1fbee68e5.tar.gz bcm5719-llvm-1271bf91783cdb0bebd701dea98907b1fbee68e5.zip |
[InstCombine] allow icmp (bit-manipulation-intrinsic(), C) folds for vectors
llvm-svn: 276523
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 29 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineInternal.h | 3 |
2 files changed, 17 insertions, 15 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index f5514a8992e..40042002936 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2355,37 +2355,35 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI, return nullptr; } -Instruction *InstCombiner::foldICmpIntrinsicWithConstant(ICmpInst &ICI, - Instruction *LHSI, - ConstantInt *RHS) { - IntrinsicInst *II = dyn_cast<IntrinsicInst>(LHSI); - if (!II || !ICI.isEquality()) +Instruction *InstCombiner::foldICmpIntrinsicWithConstant(ICmpInst &ICI) { + IntrinsicInst *II = dyn_cast<IntrinsicInst>(ICI.getOperand(0)); + const APInt *Op1C; + if (!II || !ICI.isEquality() || !match(ICI.getOperand(1), m_APInt(Op1C))) return nullptr; // Handle icmp {eq|ne} <intrinsic>, intcst. - const APInt &RHSV = RHS->getValue(); switch (II->getIntrinsicID()) { case Intrinsic::bswap: Worklist.Add(II); ICI.setOperand(0, II->getArgOperand(0)); - ICI.setOperand(1, Builder->getInt(RHSV.byteSwap())); + ICI.setOperand(1, Builder->getInt(Op1C->byteSwap())); return &ICI; case Intrinsic::ctlz: case Intrinsic::cttz: // ctz(A) == bitwidth(a) -> A == 0 and likewise for != - if (RHSV == RHS->getType()->getBitWidth()) { + if (*Op1C == Op1C->getBitWidth()) { Worklist.Add(II); ICI.setOperand(0, II->getArgOperand(0)); - ICI.setOperand(1, ConstantInt::get(RHS->getType(), 0)); + ICI.setOperand(1, ConstantInt::getNullValue(II->getType())); return &ICI; } break; case Intrinsic::ctpop: // popcount(A) == 0 -> A == 0 and likewise for != - if (RHS->isZero()) { + if (*Op1C == 0) { Worklist.Add(II); ICI.setOperand(0, II->getArgOperand(0)); - ICI.setOperand(1, RHS); + ICI.setOperand(1, ConstantInt::getNullValue(II->getType())); return &ICI; } break; @@ -3641,6 +3639,10 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { // See if we are doing a comparison between a constant and an instruction that // can be folded into the comparison. + + // FIXME: Use m_APInt instead of dyn_cast<ConstantInt> to allow these + // transforms for vectors. + if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) { // Since the RHS is a ConstantInt (CI), if the left hand side is an // instruction, see if that instruction also has constants so that the @@ -3650,11 +3652,12 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { return Res; if (Instruction *Res = foldICmpEqualityWithConstant(I, LHSI, CI)) return Res; - if (Instruction *Res = foldICmpIntrinsicWithConstant(I, LHSI, CI)) - return Res; } } + if (Instruction *Res = foldICmpIntrinsicWithConstant(I)) + return Res; + // Handle icmp with constant (but not simple integer constant) RHS if (Constant *RHSC = dyn_cast<Constant>(Op1)) { if (Instruction *LHSI = dyn_cast<Instruction>(Op0)) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 61dbd31448b..894e9a06468 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -585,8 +585,7 @@ private: ConstantInt *RHS); Instruction *foldICmpEqualityWithConstant(ICmpInst &ICI, Instruction *LHS, ConstantInt *RHS); - Instruction *foldICmpIntrinsicWithConstant(ICmpInst &ICI, Instruction *LHS, - ConstantInt *RHS); + Instruction *foldICmpIntrinsicWithConstant(ICmpInst &ICI); Instruction *OptAndOp(Instruction *Op, ConstantInt *OpRHS, ConstantInt *AndRHS, BinaryOperator &TheAnd); |