mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-20 19:42:54 +02:00
[InstCombine] Create new insts in foldICmpEqIntrinsicWithConstant; NFCI
In line with current conventions, create new instructions rather than modify two operands in place and performing manual worklist management. This should be NFC apart from possible worklist order changes.
This commit is contained in:
parent
7806a32f60
commit
9d1434bbf2
@ -3025,20 +3025,16 @@ Instruction *InstCombiner::foldICmpEqIntrinsicWithConstant(ICmpInst &Cmp,
|
||||
unsigned BitWidth = C.getBitWidth();
|
||||
switch (II->getIntrinsicID()) {
|
||||
case Intrinsic::bswap:
|
||||
Worklist.Add(II);
|
||||
Cmp.setOperand(0, II->getArgOperand(0));
|
||||
Cmp.setOperand(1, ConstantInt::get(Ty, C.byteSwap()));
|
||||
return &Cmp;
|
||||
// bswap(A) == C -> A == bswap(C)
|
||||
return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0),
|
||||
ConstantInt::get(Ty, C.byteSwap()));
|
||||
|
||||
case Intrinsic::ctlz:
|
||||
case Intrinsic::cttz: {
|
||||
// ctz(A) == bitwidth(A) -> A == 0 and likewise for !=
|
||||
if (C == BitWidth) {
|
||||
Worklist.Add(II);
|
||||
Cmp.setOperand(0, II->getArgOperand(0));
|
||||
Cmp.setOperand(1, ConstantInt::getNullValue(Ty));
|
||||
return &Cmp;
|
||||
}
|
||||
if (C == BitWidth)
|
||||
return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0),
|
||||
ConstantInt::getNullValue(Ty));
|
||||
|
||||
// ctz(A) == C -> A & Mask1 == Mask2, where Mask2 only has bit C set
|
||||
// and Mask1 has bits 0..C+1 set. Similar for ctl, but for high bits.
|
||||
@ -3051,10 +3047,9 @@ Instruction *InstCombiner::foldICmpEqIntrinsicWithConstant(ICmpInst &Cmp,
|
||||
APInt Mask2 = IsTrailing
|
||||
? APInt::getOneBitSet(BitWidth, Num)
|
||||
: APInt::getOneBitSet(BitWidth, BitWidth - Num - 1);
|
||||
Cmp.setOperand(0, Builder.CreateAnd(II->getArgOperand(0), Mask1));
|
||||
Cmp.setOperand(1, ConstantInt::get(Ty, Mask2));
|
||||
Worklist.Add(II);
|
||||
return &Cmp;
|
||||
return new ICmpInst(Cmp.getPredicate(),
|
||||
Builder.CreateAnd(II->getArgOperand(0), Mask1),
|
||||
ConstantInt::get(Ty, Mask2));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -3063,14 +3058,10 @@ Instruction *InstCombiner::foldICmpEqIntrinsicWithConstant(ICmpInst &Cmp,
|
||||
// popcount(A) == 0 -> A == 0 and likewise for !=
|
||||
// popcount(A) == bitwidth(A) -> A == -1 and likewise for !=
|
||||
bool IsZero = C.isNullValue();
|
||||
if (IsZero || C == BitWidth) {
|
||||
Worklist.Add(II);
|
||||
Cmp.setOperand(0, II->getArgOperand(0));
|
||||
auto *NewOp =
|
||||
IsZero ? Constant::getNullValue(Ty) : Constant::getAllOnesValue(Ty);
|
||||
Cmp.setOperand(1, NewOp);
|
||||
return &Cmp;
|
||||
}
|
||||
if (IsZero || C == BitWidth)
|
||||
return new ICmpInst(Cmp.getPredicate(), II->getArgOperand(0),
|
||||
IsZero ? Constant::getNullValue(Ty) : Constant::getAllOnesValue(Ty));
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3078,9 +3069,7 @@ Instruction *InstCombiner::foldICmpEqIntrinsicWithConstant(ICmpInst &Cmp,
|
||||
// uadd.sat(a, b) == 0 -> (a | b) == 0
|
||||
if (C.isNullValue()) {
|
||||
Value *Or = Builder.CreateOr(II->getArgOperand(0), II->getArgOperand(1));
|
||||
return replaceInstUsesWith(Cmp, Builder.CreateICmp(
|
||||
Cmp.getPredicate(), Or, Constant::getNullValue(Ty)));
|
||||
|
||||
return new ICmpInst(Cmp.getPredicate(), Or, Constant::getNullValue(Ty));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -3090,8 +3079,7 @@ Instruction *InstCombiner::foldICmpEqIntrinsicWithConstant(ICmpInst &Cmp,
|
||||
if (C.isNullValue()) {
|
||||
ICmpInst::Predicate NewPred = Cmp.getPredicate() == ICmpInst::ICMP_EQ
|
||||
? ICmpInst::ICMP_ULE : ICmpInst::ICMP_UGT;
|
||||
return ICmpInst::Create(Instruction::ICmp, NewPred,
|
||||
II->getArgOperand(0), II->getArgOperand(1));
|
||||
return new ICmpInst(NewPred, II->getArgOperand(0), II->getArgOperand(1));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user