[llvm] 9eda781 - [ConstraintElim] Fix sort order to not comparing insts in different bbs.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 15:47:46 PST 2022


Author: Florian Hahn
Date: 2022-12-06T23:47:24Z
New Revision: 9eda78107c4d9baca947b7bd9e0ce1c72474a59b

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

LOG: [ConstraintElim] Fix sort order to not comparing insts in different bbs.

Update the sort order to make sure that comesBefore is never used from
conditional facts, which are instructions but may use DFS numbers from
different blocks.

This fixes a crash in the added test on some platforms.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index ba932776c021e..280ca3b700df6 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -955,15 +955,15 @@ static bool eliminateConstraints(Function &F, DominatorTree &DT) {
     // If both entries have the same In numbers, conditional facts come first.
     // Otherwise use the relative order in the basic block.
     if (A.NumIn == B.NumIn) {
-      if (A.isConditionFact() && B.IsCheck)
-        return true;
-      if (B.isConditionFact() && A.IsCheck)
-        return false;
       if (A.isConditionFact() && B.isConditionFact()) {
         bool NoConstOpA = HasNoConstOp(A);
         bool NoConstOpB = HasNoConstOp(B);
         return NoConstOpA < NoConstOpB;
       }
+      if (A.isConditionFact())
+        return true;
+      if (B.isConditionFact())
+        return false;
       return A.Inst->comesBefore(B.Inst);
     }
     return A.NumIn < B.NumIn;

diff  --git a/llvm/test/Transforms/ConstraintElimination/assumes.ll b/llvm/test/Transforms/ConstraintElimination/assumes.ll
index 0675f97b5b713..199c9660117db 100644
--- a/llvm/test/Transforms/ConstraintElimination/assumes.ll
+++ b/llvm/test/Transforms/ConstraintElimination/assumes.ll
@@ -595,3 +595,30 @@ define i1 @all_uses_after_assume(i8 %a, i8 %b, i1 %c) {
   %res.2 = xor i1 %res.1, %c.2
   ret i1 %res.2
 }
+
+define i1 @test_order_assume_and_conds_in_
diff erent_bb(i16 %a, ptr %dst) {
+; CHECK-LABEL: @test_order_assume_and_conds_in_
diff erent_bb(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult i16 [[A:%.*]], 10
+; CHECK-NEXT:    br i1 [[C_1]], label [[THEN:%.*]], label [[ELSE:%.*]]
+; CHECK:       then:
+; CHECK-NEXT:    ret i1 false
+; CHECK:       else:
+; CHECK-NEXT:    store volatile float 0.000000e+00, ptr [[DST:%.*]], align 4
+; CHECK-NEXT:    [[C_2:%.*]] = icmp eq i16 [[A]], 20
+; CHECK-NEXT:    tail call void @llvm.assume(i1 [[C_2]])
+; CHECK-NEXT:    ret i1 [[C_2]]
+;
+entry:
+  %c.1 = icmp ult i16 %a, 10
+  br i1 %c.1, label %then, label %else
+
+then:
+  ret i1 0
+
+else:
+  store volatile float 0.000000e+00, ptr %dst
+  %c.2 = icmp eq i16 %a, 20
+  tail call void @llvm.assume(i1 %c.2)
+  ret i1 %c.2
+}


        


More information about the llvm-commits mailing list