[llvm] 13042da - [ConstraintElimination] Add support for And.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 17 06:12:32 PST 2020


Author: Florian Hahn
Date: 2020-11-17T14:12:15Z
New Revision: 13042da5cb3fe5f17c58c2446c93635a2c432049

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

LOG: [ConstraintElimination] Add support for And.

When processing conditional branches, if the condition is an AND of 2 compares
and the true successor only has the current block as predecessor, queue both
conditions for the true successor.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index c43cb39a5918..01fead12dc08 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -182,6 +182,21 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
       continue;
     }
 
+    // If the condition is an AND of 2 compares and the true successor only has
+    // the current block as predecessor, queue both conditions for the true
+    // successor.
+    if (match(Br->getCondition(), m_And(m_Cmp(), m_Cmp()))) {
+      BasicBlock *TrueSuccessor = Br->getSuccessor(0);
+      if (TrueSuccessor->getSinglePredecessor()) {
+        auto *AndI = cast<Instruction>(Br->getCondition());
+        WorkList.emplace_back(DT.getNode(TrueSuccessor),
+                              cast<CmpInst>(AndI->getOperand(0)), false);
+        WorkList.emplace_back(DT.getNode(TrueSuccessor),
+                              cast<CmpInst>(AndI->getOperand(1)), false);
+      }
+      continue;
+    }
+
     auto *CmpI = dyn_cast<CmpInst>(Br->getCondition());
     if (!CmpI)
       continue;

diff  --git a/llvm/test/Transforms/ConstraintElimination/and.ll b/llvm/test/Transforms/ConstraintElimination/and.ll
index 2e7f61659dac..d8962b39ebd5 100644
--- a/llvm/test/Transforms/ConstraintElimination/and.ll
+++ b/llvm/test/Transforms/ConstraintElimination/and.ll
@@ -12,11 +12,11 @@ define i32 @test_and_ule(i32 %x, i32 %y, i32 %z, i32 %a) {
 ; CHECK-NEXT:    br i1 [[AND]], label [[BB1:%.*]], label [[EXIT:%.*]]
 ; CHECK:       bb1:
 ; CHECK-NEXT:    [[T_1:%.*]] = icmp ule i32 [[X]], [[Z]]
-; CHECK-NEXT:    call void @use(i1 [[T_1]])
+; CHECK-NEXT:    call void @use(i1 true)
 ; CHECK-NEXT:    [[T_2:%.*]] = icmp ule i32 [[X]], [[Y]]
-; CHECK-NEXT:    call void @use(i1 [[T_2]])
+; CHECK-NEXT:    call void @use(i1 true)
 ; CHECK-NEXT:    [[T_3:%.*]] = icmp ule i32 [[Y]], [[Z]]
-; CHECK-NEXT:    call void @use(i1 [[T_3]])
+; CHECK-NEXT:    call void @use(i1 true)
 ; CHECK-NEXT:    [[C_3:%.*]] = icmp ule i32 [[X]], [[A:%.*]]
 ; CHECK-NEXT:    call void @use(i1 [[C_3]])
 ; CHECK-NEXT:    ret i32 10


        


More information about the llvm-commits mailing list