@@ -993,7 +993,8 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
993
993
return nullptr ;
994
994
}
995
995
996
- Instruction *InstCombinerImpl::transformZExtICmp (ICmpInst *Cmp, ZExtInst &Zext) {
996
+ Instruction *InstCombinerImpl::transformZExtICmp (ICmpInst *Cmp,
997
+ ZExtInst &Zext) {
997
998
// If we are just checking for a icmp eq of a single bit and zext'ing it
998
999
// to an integer, then shift the bit to the appropriate place and then
999
1000
// cast to integer to avoid the comparison.
@@ -1031,8 +1032,8 @@ Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext)
1031
1032
// canonicalized to this form.
1032
1033
APInt KnownZeroMask (~Known.Zero );
1033
1034
if (KnownZeroMask.isPowerOf2 () &&
1034
- (Zext.getType ()->getScalarSizeInBits () != KnownZeroMask. logBase2 () + 1 )) {
1035
- bool isNE = Cmp-> getPredicate () == ICmpInst::ICMP_NE;
1035
+ (Zext.getType ()->getScalarSizeInBits () !=
1036
+ KnownZeroMask. logBase2 () + 1 )) {
1036
1037
uint32_t ShAmt = KnownZeroMask.logBase2 ();
1037
1038
Value *In = Cmp->getOperand (0 );
1038
1039
if (ShAmt) {
@@ -1042,10 +1043,9 @@ Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext)
1042
1043
In->getName () + " .lobit" );
1043
1044
}
1044
1045
1045
- if (!isNE) { // Toggle the low bit.
1046
- Constant *One = ConstantInt::get (In->getType (), 1 );
1047
- In = Builder.CreateXor (In, One);
1048
- }
1046
+ // Toggle the low bit for "X == 0".
1047
+ if (Cmp->getPredicate () == ICmpInst::ICMP_EQ)
1048
+ In = Builder.CreateXor (In, ConstantInt::get (In->getType (), 1 ));
1049
1049
1050
1050
if (Zext.getType () == In->getType ())
1051
1051
return replaceInstUsesWith (Zext, In);
0 commit comments