[InstCombine] Use KnownBits::udiv() helper
authorNikita Popov <npopov@redhat.com>
Wed, 17 May 2023 15:01:58 +0000 (17:01 +0200)
committerNikita Popov <npopov@redhat.com>
Wed, 17 May 2023 15:03:35 +0000 (17:03 +0200)
This produces more precise results than the ad-hoc implementation.

Noticed while trying to add a consistency assertion.

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

index c9c7f4a..0d0522a 100644 (file)
@@ -808,9 +808,8 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
         return I;
       }
 
-      // Increase high zero bits from the input.
-      Known.Zero.setHighBits(
-          std::min(BitWidth, LHSKnown.Zero.countl_one() + RHSTrailingZeros));
+      Known = KnownBits::udiv(LHSKnown, KnownBits::makeConstant(*SA),
+                              cast<BinaryOperator>(I)->isExact());
     } else {
       computeKnownBits(I, Known, Depth, CxtI);
     }