[llvm] 4ca30de - [InstCombine] Use KnownBits::urem() helper

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed May 17 08:15:03 PDT 2023


Author: Nikita Popov
Date: 2023-05-17T17:14:54+02:00
New Revision: 4ca30ded4f07b192b8a8bed069400f9d6b85a792

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

LOG: [InstCombine] Use KnownBits::urem() helper

This provides more precise results than the ad-hoc implementation.
Noticed while trying to add a consistency assertion.

To be honest I'm not sure why this code exists at all -- the
recursive calls are done with all bits demanded, so this should
be equivalent to just using the default case.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 0d0522a18349..c00bc74191a0 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -855,14 +855,12 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
     break;
   }
   case Instruction::URem: {
-    KnownBits Known2(BitWidth);
     APInt AllOnes = APInt::getAllOnes(BitWidth);
-    if (SimplifyDemandedBits(I, 0, AllOnes, Known2, Depth + 1) ||
-        SimplifyDemandedBits(I, 1, AllOnes, Known2, Depth + 1))
+    if (SimplifyDemandedBits(I, 0, AllOnes, LHSKnown, Depth + 1) ||
+        SimplifyDemandedBits(I, 1, AllOnes, RHSKnown, Depth + 1))
       return I;
 
-    unsigned Leaders = Known2.countMinLeadingZeros();
-    Known.Zero = APInt::getHighBitsSet(BitWidth, Leaders) & DemandedMask;
+    Known = KnownBits::urem(LHSKnown, RHSKnown);
     break;
   }
   case Instruction::Call: {


        


More information about the llvm-commits mailing list