return nullptr;
}
-Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext) {
+Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp,
+ ZExtInst &Zext) {
// If we are just checking for a icmp eq of a single bit and zext'ing it
// to an integer, then shift the bit to the appropriate place and then
// cast to integer to avoid the comparison.
// canonicalized to this form.
APInt KnownZeroMask(~Known.Zero);
if (KnownZeroMask.isPowerOf2() &&
- (Zext.getType()->getScalarSizeInBits() != KnownZeroMask.logBase2() + 1)) {
- bool isNE = Cmp->getPredicate() == ICmpInst::ICMP_NE;
+ (Zext.getType()->getScalarSizeInBits() !=
+ KnownZeroMask.logBase2() + 1)) {
uint32_t ShAmt = KnownZeroMask.logBase2();
Value *In = Cmp->getOperand(0);
if (ShAmt) {
In->getName() + ".lobit");
}
- if (!isNE) { // Toggle the low bit.
- Constant *One = ConstantInt::get(In->getType(), 1);
- In = Builder.CreateXor(In, One);
- }
+ // Toggle the low bit for "X == 0".
+ if (Cmp->getPredicate() == ICmpInst::ICMP_EQ)
+ In = Builder.CreateXor(In, ConstantInt::get(In->getType(), 1));
if (Zext.getType() == In->getType())
return replaceInstUsesWith(Zext, In);