[InstCombine] Use computeKnownBits() for srem SimplifyDemandedBits()
authorNikita Popov <npopov@redhat.com>
Wed, 17 May 2023 13:54:11 +0000 (15:54 +0200)
committerNikita Popov <npopov@redhat.com>
Wed, 17 May 2023 13:57:23 +0000 (15:57 +0200)
For the case of a non-constant operand, fall back to
computeKnownBits() rather than trying to reimplement logic.

Found while testing a consistency assertion for both functions.

llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp

index 231739d..c9c7f4a 100644 (file)
@@ -852,14 +852,7 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
       }
     }
 
-    // The sign bit is the LHS's sign bit, except when the result of the
-    // remainder is zero.
-    if (DemandedMask.isSignBitSet()) {
-      computeKnownBits(I->getOperand(0), LHSKnown, Depth + 1, CxtI);
-      // If it's known zero, our sign bit is also zero.
-      if (LHSKnown.isNonNegative())
-        Known.makeNonNegative();
-    }
+    computeKnownBits(I, Known, Depth, CxtI);
     break;
   }
   case Instruction::URem: {