[llvm] 5ef02a3 - [InstCombine] Fall through to computeKnownBits() for sdiv by -1

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 05:23:14 PDT 2024


Author: Nikita Popov
Date: 2024-09-25T14:23:06+02:00
New Revision: 5ef02a3fd4758ae1b9151ac581eebd1109b4daad

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

LOG: [InstCombine] Fall through to computeKnownBits() for sdiv by -1

When dividing by -1 we were breaking out of the code entirely,
while we should fall through to computeKnownBits().

This fixes an instcombine-verify-known-bits discrepancy.

Fixes https://github.com/llvm/llvm-project/issues/109957.

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 9c4d206692fac6..c66db9285c799a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -858,11 +858,9 @@ Value *InstCombinerImpl::SimplifyDemandedUseBits(Instruction *I,
   }
   case Instruction::SRem: {
     const APInt *Rem;
-    if (match(I->getOperand(1), m_APInt(Rem))) {
-      // X % -1 demands all the bits because we don't want to introduce
-      // INT_MIN % -1 (== undef) by accident.
-      if (Rem->isAllOnes())
-        break;
+    // X % -1 demands all the bits because we don't want to introduce
+    // INT_MIN % -1 (== undef) by accident.
+    if (match(I->getOperand(1), m_APInt(Rem)) && !Rem->isAllOnes()) {
       APInt RA = Rem->abs();
       if (RA.isPowerOf2()) {
         if (DemandedMask.ult(RA))    // srem won't affect demanded bits


        


More information about the llvm-commits mailing list