mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[InstCombine] reduce code duplication in icmp intrinsic folds; NFC
This commit is contained in:
parent
be7bad8bb6
commit
f7a844a775
@ -3172,10 +3172,11 @@ Instruction *InstCombinerImpl::foldICmpIntrinsicWithConstant(ICmpInst &Cmp,
|
||||
|
||||
Type *Ty = II->getType();
|
||||
unsigned BitWidth = C.getBitWidth();
|
||||
ICmpInst::Predicate Pred = Cmp.getPredicate();
|
||||
switch (II->getIntrinsicID()) {
|
||||
case Intrinsic::ctlz: {
|
||||
// ctlz(0bXXXXXXXX) > 3 -> 0bXXXXXXXX < 0b00010000
|
||||
if (Cmp.getPredicate() == ICmpInst::ICMP_UGT && C.ult(BitWidth)) {
|
||||
if (Pred == ICmpInst::ICMP_UGT && C.ult(BitWidth)) {
|
||||
unsigned Num = C.getLimitedValue();
|
||||
APInt Limit = APInt::getOneBitSet(BitWidth, BitWidth - Num - 1);
|
||||
return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_ULT,
|
||||
@ -3183,8 +3184,7 @@ Instruction *InstCombinerImpl::foldICmpIntrinsicWithConstant(ICmpInst &Cmp,
|
||||
}
|
||||
|
||||
// ctlz(0bXXXXXXXX) < 3 -> 0bXXXXXXXX > 0b00011111
|
||||
if (Cmp.getPredicate() == ICmpInst::ICMP_ULT &&
|
||||
C.uge(1) && C.ule(BitWidth)) {
|
||||
if (Pred == ICmpInst::ICMP_ULT && C.uge(1) && C.ule(BitWidth)) {
|
||||
unsigned Num = C.getLimitedValue();
|
||||
APInt Limit = APInt::getLowBitsSet(BitWidth, BitWidth - Num);
|
||||
return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_UGT,
|
||||
@ -3198,7 +3198,7 @@ Instruction *InstCombinerImpl::foldICmpIntrinsicWithConstant(ICmpInst &Cmp,
|
||||
return nullptr;
|
||||
|
||||
// cttz(0bXXXXXXXX) > 3 -> 0bXXXXXXXX & 0b00001111 == 0
|
||||
if (Cmp.getPredicate() == ICmpInst::ICMP_UGT && C.ult(BitWidth)) {
|
||||
if (Pred == ICmpInst::ICMP_UGT && C.ult(BitWidth)) {
|
||||
APInt Mask = APInt::getLowBitsSet(BitWidth, C.getLimitedValue() + 1);
|
||||
return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_EQ,
|
||||
Builder.CreateAnd(II->getArgOperand(0), Mask),
|
||||
@ -3206,8 +3206,7 @@ Instruction *InstCombinerImpl::foldICmpIntrinsicWithConstant(ICmpInst &Cmp,
|
||||
}
|
||||
|
||||
// cttz(0bXXXXXXXX) < 3 -> 0bXXXXXXXX & 0b00000111 != 0
|
||||
if (Cmp.getPredicate() == ICmpInst::ICMP_ULT &&
|
||||
C.uge(1) && C.ule(BitWidth)) {
|
||||
if (Pred == ICmpInst::ICMP_ULT && C.uge(1) && C.ule(BitWidth)) {
|
||||
APInt Mask = APInt::getLowBitsSet(BitWidth, C.getLimitedValue());
|
||||
return CmpInst::Create(Instruction::ICmp, ICmpInst::ICMP_NE,
|
||||
Builder.CreateAnd(II->getArgOperand(0), Mask),
|
||||
|
Loading…
x
Reference in New Issue
Block a user