[InstCombine] simplify code and fix formatting; NFC
authorSanjay Patel <spatel@rotateright.com>
Mon, 9 Jan 2023 21:27:44 +0000 (16:27 -0500)
committerSanjay Patel <spatel@rotateright.com>
Mon, 9 Jan 2023 21:27:44 +0000 (16:27 -0500)
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

index 6c59185..7b17a8b 100644 (file)
@@ -993,7 +993,8 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
   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.
@@ -1031,8 +1032,8 @@ Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext)
       // 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) {
@@ -1042,10 +1043,9 @@ Instruction *InstCombinerImpl::transformZExtICmp(ICmpInst *Cmp, ZExtInst &Zext)
                                   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);