[llvm] 782e912 - [ConstraintElimination] Support constraints with only const ops.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 14 02:37:56 PDT 2022


Author: Florian Hahn
Date: 2022-06-14T10:37:12+01:00
New Revision: 782e91224601e461c019e0a4573bbccc6094fbcd

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

LOG: [ConstraintElimination] Support constraints with only const ops.

Remove the early exit if both constraints contain no variables. This
restriction is unnecessayr for correctness and removing it simplifies
handling of trivial constant conditions in follow-up changes.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
    llvm/test/Transforms/ConstraintElimination/constants.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index a2b62fb10097d..7c6d696256ba5 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -282,10 +282,6 @@ getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
   if (ADec.empty() || BDec.empty())
     return {};
 
-  // Skip trivial constraints without any variables.
-  if (ADec.size() == 1 && BDec.size() == 1)
-    return {};
-
   int64_t Offset1 = ADec[0].first;
   int64_t Offset2 = BDec[0].first;
   Offset1 *= -1;
@@ -350,7 +346,7 @@ bool ConstraintTy::isValid(const ConstraintInfo &Info) const {
                Info.getValue2Index(CmpInst::isSigned(C.Pred)), NewIndices);
            // TODO: properly check NewIndices.
            return NewIndices.empty() && R.Preconditions.empty() && !R.IsEq &&
-                  R.size() >= 2 &&
+                  R.size() >= 1 &&
                   Info.getCS(CmpInst::isSigned(C.Pred))
                       .isConditionImplied(R.Coefficients);
          });
@@ -631,7 +627,7 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
 
         DenseMap<Value *, unsigned> NewIndices;
         auto R = getConstraint(Cmp, Info, NewIndices);
-        if (R.IsEq || R.size() < 2 || R.needsNewIndices(NewIndices) ||
+        if (R.IsEq || R.empty() || R.needsNewIndices(NewIndices) ||
             !R.isValid(Info))
           continue;
 

diff  --git a/llvm/test/Transforms/ConstraintElimination/constants.ll b/llvm/test/Transforms/ConstraintElimination/constants.ll
index eeb81244ef39a..896eb07aff132 100644
--- a/llvm/test/Transforms/ConstraintElimination/constants.ll
+++ b/llvm/test/Transforms/ConstraintElimination/constants.ll
@@ -6,11 +6,11 @@ define i1 @test_ult() {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[T_0:%.*]] = icmp ult i8 10, 11
 ; CHECK-NEXT:    [[F_0:%.*]] = icmp ult i8 10, 10
-; CHECK-NEXT:    [[RES_1:%.*]] = xor i1 [[T_0]], [[F_0]]
+; CHECK-NEXT:    [[RES_1:%.*]] = xor i1 true, false
 ; CHECK-NEXT:    [[F_1:%.*]] = icmp ult i8 10, 9
-; CHECK-NEXT:    [[RES_2:%.*]] = xor i1 [[RES_1]], [[F_1]]
+; CHECK-NEXT:    [[RES_2:%.*]] = xor i1 [[RES_1]], false
 ; CHECK-NEXT:    [[T_1:%.*]] = icmp ult i8 10, -10
-; CHECK-NEXT:    [[RES_3:%.*]] = xor i1 [[RES_2]], [[T_1]]
+; CHECK-NEXT:    [[RES_3:%.*]] = xor i1 [[RES_2]], true
 ; CHECK-NEXT:    ret i1 [[RES_3]]
 ;
 entry:
@@ -75,11 +75,11 @@ define i1 @test_slt() {
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[T_0:%.*]] = icmp ult i8 10, 11
 ; CHECK-NEXT:    [[F_0:%.*]] = icmp ult i8 10, 10
-; CHECK-NEXT:    [[RES_1:%.*]] = xor i1 [[T_0]], [[F_0]]
+; CHECK-NEXT:    [[RES_1:%.*]] = xor i1 true, false
 ; CHECK-NEXT:    [[F_1:%.*]] = icmp ult i8 10, 9
-; CHECK-NEXT:    [[RES_2:%.*]] = xor i1 [[RES_1]], [[F_1]]
+; CHECK-NEXT:    [[RES_2:%.*]] = xor i1 [[RES_1]], false
 ; CHECK-NEXT:    [[F_2:%.*]] = icmp ult i8 10, -10
-; CHECK-NEXT:    [[RES_3:%.*]] = xor i1 [[RES_2]], [[F_2]]
+; CHECK-NEXT:    [[RES_3:%.*]] = xor i1 [[RES_2]], true
 ; CHECK-NEXT:    ret i1 [[RES_3]]
 ;
 entry:


        


More information about the llvm-commits mailing list