[llvm] a4f3b23 - [InstCombine] simplify code and fix formatting; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 13:30:24 PST 2023


Author: Sanjay Patel
Date: 2023-01-09T16:27:44-05:00
New Revision: a4f3b236719529bdc987d4f347e8711c27587ce4

URL: https://github.com/llvm/llvm-project/commit/a4f3b236719529bdc987d4f347e8711c27587ce4
DIFF: https://github.com/llvm/llvm-project/commit/a4f3b236719529bdc987d4f347e8711c27587ce4.diff

LOG: [InstCombine] simplify code and fix formatting; NFC

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 6c5918507b6e2..7b17a8b9757a3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -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);


        


More information about the llvm-commits mailing list