[llvm] bdfe986 - [ConstraintElimination] Simplify logic for using inverse predicate (NFC)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 10:36:22 PDT 2022


Author: Florian Hahn
Date: 2022-10-03T18:35:59+01:00
New Revision: bdfe986d6601127cf5c31055a8085b0a47af2af6

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

LOG: [ConstraintElimination] Simplify logic for using inverse predicate (NFC)

Recent improvements to the code structure mean we don't need to reset
the condition's predicate in the IR and later restore it. Remove the
restorer logic.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index efb142dad6e8..6cfe83934b55 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -852,25 +852,13 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
       continue;
     }
 
-    // Set up a function to restore the predicate at the end of the scope if it
-    // has been negated. Negate the predicate in-place, if required.
-    auto *CI = dyn_cast<ICmpInst>(CB.Condition);
-    auto PredicateRestorer = make_scope_exit([CI, &CB]() {
-      if (CB.Not && CI)
-        CI->setPredicate(CI->getInversePredicate());
-    });
-    if (CB.Not) {
-      if (CI) {
-        CI->setPredicate(CI->getInversePredicate());
-      } else {
-        LLVM_DEBUG(dbgs() << "Can only negate compares so far.\n");
-        continue;
-      }
-    }
-
     ICmpInst::Predicate Pred;
     Value *A, *B;
     if (match(CB.Condition, m_ICmp(Pred, m_Value(A), m_Value(B)))) {
+      // Use the inverse predicate if required.
+      if (CB.Not)
+        Pred = CmpInst::getInversePredicate(Pred);
+
       Info.addFact(Pred, A, B, CB.NumIn, CB.NumOut, DFSInStack);
       Info.transferToOtherSystem(Pred, A, B, CB.NumIn, CB.NumOut, DFSInStack);
     }


        


More information about the llvm-commits mailing list