[llvm] 7dbeb12 - [InstSimplify] X && !(X || Y) --> false

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 26 10:42:53 PST 2023


Author: Sanjay Patel
Date: 2023-01-26T13:38:43-05:00
New Revision: 7dbeb127eaf6639aa7d0839ade964cf6f1528597

URL: https://github.com/llvm/llvm-project/commit/7dbeb127eaf6639aa7d0839ade964cf6f1528597
DIFF: https://github.com/llvm/llvm-project/commit/7dbeb127eaf6639aa7d0839ade964cf6f1528597.diff

LOG: [InstSimplify] X && !(X || Y) --> false

https://alive2.llvm.org/ce/z/7J8Exr

This is a commuted variant that was not included in:
D138853 / f2973327496fc966c4e89597

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp
    llvm/test/Transforms/InstSimplify/select-logical.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index c83eb96bbc69..e2154ca55c3e 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4598,6 +4598,9 @@ static Value *simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
       // !(X || Y) && X --> false (commuted 2 ways)
       if (match(Cond, m_Not(m_c_LogicalOr(m_Specific(TrueVal), m_Value()))))
         return ConstantInt::getFalse(Cond->getType());
+      // X && !(X || Y) --> false (commuted 2 ways)
+      if (match(TrueVal, m_Not(m_c_LogicalOr(m_Specific(Cond), m_Value()))))
+        return ConstantInt::getFalse(Cond->getType());
 
       // (X || Y) && Y --> Y (commuted 2 ways)
       if (match(Cond, m_c_LogicalOr(m_Specific(TrueVal), m_Value())))

diff  --git a/llvm/test/Transforms/InstSimplify/select-logical.ll b/llvm/test/Transforms/InstSimplify/select-logical.ll
index 0fa9c68ac6d2..e2b124ce3df5 100644
--- a/llvm/test/Transforms/InstSimplify/select-logical.ll
+++ b/llvm/test/Transforms/InstSimplify/select-logical.ll
@@ -200,10 +200,7 @@ define i1 @logical_or_not_and_commute_or(i1 %x, i1 %y) {
 
 define i1 @logical_or_not_commute_and(i1 %x, i1 %y) {
 ; CHECK-LABEL: @logical_or_not_commute_and(
-; CHECK-NEXT:    [[L_AND:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
-; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[L_AND]], true
-; CHECK-NEXT:    [[R:%.*]] = select i1 [[X]], i1 [[NOT]], i1 false
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 false
 ;
   %l.and = select i1 %x, i1 true, i1 %y
   %not = xor i1 %l.and, true
@@ -215,10 +212,7 @@ define i1 @logical_or_not_commute_and(i1 %x, i1 %y) {
 
 define i1 @logical_or_not_commute_and_commute_or(i1 %x, i1 %y) {
 ; CHECK-LABEL: @logical_or_not_commute_and_commute_or(
-; CHECK-NEXT:    [[L_AND:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
-; CHECK-NEXT:    [[NOT:%.*]] = xor i1 [[L_AND]], true
-; CHECK-NEXT:    [[R:%.*]] = select i1 [[Y]], i1 [[NOT]], i1 false
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 false
 ;
   %l.and = select i1 %x, i1 true, i1 %y
   %not = xor i1 %l.and, true


        


More information about the llvm-commits mailing list