[llvm] 062058e - [InstCombine] Use analyzeKnownBitsFromAndXorOr() in multi-use demanded bits

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 05:22:58 PST 2023


Author: Nikita Popov
Date: 2023-11-30T14:22:48+01:00
New Revision: 062058ef36c3a5a41f5c2ad2fd1a53f7a099e956

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

LOG: [InstCombine] Use analyzeKnownBitsFromAndXorOr() in multi-use demanded bits

We were using this helper in single-use demanded bits but not
multi-use demanded bits.

This fixes an assertion failure when asserting consistency between
computeKnownBits() and SimplifyDemandedBits().

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 a4b17372e44b3e7..5f705d6882c60d7 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -1056,7 +1056,8 @@ Value *InstCombinerImpl::SimplifyMultipleUseDemandedBits(
   case Instruction::And: {
     computeKnownBits(I->getOperand(1), RHSKnown, Depth + 1, CxtI);
     computeKnownBits(I->getOperand(0), LHSKnown, Depth + 1, CxtI);
-    Known = LHSKnown & RHSKnown;
+    Known = analyzeKnownBitsFromAndXorOr(cast<Operator>(I), LHSKnown, RHSKnown,
+                                         Depth, SQ.getWithInstruction(CxtI));
     computeKnownBitsFromContext(I, Known, Depth, SQ.getWithInstruction(CxtI));
 
     // If the client is only demanding bits that we know, return the known
@@ -1076,7 +1077,8 @@ Value *InstCombinerImpl::SimplifyMultipleUseDemandedBits(
   case Instruction::Or: {
     computeKnownBits(I->getOperand(1), RHSKnown, Depth + 1, CxtI);
     computeKnownBits(I->getOperand(0), LHSKnown, Depth + 1, CxtI);
-    Known = LHSKnown | RHSKnown;
+    Known = analyzeKnownBitsFromAndXorOr(cast<Operator>(I), LHSKnown, RHSKnown,
+                                         Depth, SQ.getWithInstruction(CxtI));
     computeKnownBitsFromContext(I, Known, Depth, SQ.getWithInstruction(CxtI));
 
     // If the client is only demanding bits that we know, return the known
@@ -1098,7 +1100,8 @@ Value *InstCombinerImpl::SimplifyMultipleUseDemandedBits(
   case Instruction::Xor: {
     computeKnownBits(I->getOperand(1), RHSKnown, Depth + 1, CxtI);
     computeKnownBits(I->getOperand(0), LHSKnown, Depth + 1, CxtI);
-    Known = LHSKnown ^ RHSKnown;
+    Known = analyzeKnownBitsFromAndXorOr(cast<Operator>(I), LHSKnown, RHSKnown,
+                                         Depth, SQ.getWithInstruction(CxtI));
     computeKnownBitsFromContext(I, Known, Depth, SQ.getWithInstruction(CxtI));
 
     // If the client is only demanding bits that we know, return the known


        


More information about the llvm-commits mailing list