[llvm] b63fc26 - [InstSimplify] make uses of isImpliedCondition more efficient (NFCI)

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 5 09:06:52 PDT 2022


Author: Sanjay Patel
Date: 2022-08-05T12:06:47-04:00
New Revision: b63fc26d33e16698e015d5942b4065fbacf44909

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

LOG: [InstSimplify] make uses of isImpliedCondition more efficient (NFCI)

As suggested in the post-commit comments for 019d76196f79fcff3c148,
this makes the usage symmetric with the 'and' patterns and should
be more efficient.

Added: 
    

Modified: 
    llvm/lib/Analysis/InstructionSimplify.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 95783607a0b2..30b9c6e4ef9d 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -2421,23 +2421,19 @@ static Value *simplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q,
       return V;
 
   if (Op0->getType()->isIntOrIntVectorTy(1)) {
-    // If Op0 is true implies Op1 is true, then Op0 is a subset of Op1.
-    if (Optional<bool> Implied = isImpliedCondition(Op0, Op1, Q.DL)) {
-      if (*Implied == true)
-        return Op1;
-    }
-    // If Op0 is false implies Op1 is true, then at least one is always true.
     if (Optional<bool> Implied = isImpliedCondition(Op0, Op1, Q.DL, false)) {
+      // If Op0 is false implies Op1 is false, then Op1 is a subset of Op0.
+      if (*Implied == false)
+        return Op0;
+      // If Op0 is false implies Op1 is true, then at least one is always true.
       if (*Implied == true)
         return ConstantInt::getTrue(Op0->getType());
     }
-    // If Op1 is true implies Op0 is true, then Op1 is a subset of Op0.
-    if (Optional<bool> Implied = isImpliedCondition(Op1, Op0, Q.DL)) {
-      if (*Implied == true)
-        return Op0;
-    }
-    // If Op1 is false implies Op0 is true, then at least one is always true.
     if (Optional<bool> Implied = isImpliedCondition(Op1, Op0, Q.DL, false)) {
+      // If Op1 is false implies Op0 is false, then Op0 is a subset of Op1.
+      if (*Implied == false)
+        return Op1;
+      // If Op1 is false implies Op0 is true, then at least one is always true.
       if (*Implied == true)
         return ConstantInt::getTrue(Op1->getType());
     }


        


More information about the llvm-commits mailing list