[llvm] 3602d85 - [Test] One more test where check is not replaced to invariant

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 04:26:56 PST 2023


Author: Max Kazantsev
Date: 2023-01-09T19:26:48+07:00
New Revision: 3602d852a5abe42b108faa2556772aa165466e88

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

LOG: [Test] One more test where check is not replaced to invariant

Irrelevant constant check makes things even more difficult, surprisingly.

Added: 
    

Modified: 
    llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll b/llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll
index 83dce99befad..9bab1caf6041 100644
--- a/llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll
+++ b/llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll
@@ -841,3 +841,80 @@ done:
 failed:
   ret i32 -3
 }
+
+; TODO: Same as test_litter_conditions, but an extra check with known exact exit count is preventing the opt.
+define i32 @test_litter_conditions_constant(i32 %start, i32 %len) {
+; CHECK-LABEL: @test_litter_conditions_constant(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    br label [[LOOP:%.*]]
+; CHECK:       loop:
+; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
+; CHECK-NEXT:    [[CANONICAL_IV:%.*]] = phi i32 [ 0, [[ENTRY]] ], [ [[CANONICAL_IV_NEXT:%.*]], [[BACKEDGE]] ]
+; CHECK-NEXT:    [[CONSTANT_CHECK:%.*]] = icmp ult i32 [[CANONICAL_IV]], 65635
+; CHECK-NEXT:    br i1 [[CONSTANT_CHECK]], label [[CONSTANT_CHECK_PASSED:%.*]], label [[CONSTANT_CHECK_FAILED:%.*]]
+; CHECK:       constant_check_passed:
+; CHECK-NEXT:    [[ZERO_CHECK:%.*]] = icmp ne i32 [[IV]], 0
+; CHECK-NEXT:    [[FAKE_1:%.*]] = call i1 @cond()
+; CHECK-NEXT:    [[AND_1:%.*]] = and i1 [[ZERO_CHECK]], [[FAKE_1]]
+; CHECK-NEXT:    br i1 [[AND_1]], label [[RANGE_CHECK_BLOCK:%.*]], label [[FAILED_1:%.*]]
+; CHECK:       range_check_block:
+; CHECK-NEXT:    [[IV_MINUS_1:%.*]] = add i32 [[IV]], -1
+; CHECK-NEXT:    [[RANGE_CHECK:%.*]] = icmp ult i32 [[IV_MINUS_1]], [[LEN:%.*]]
+; CHECK-NEXT:    [[FAKE_2:%.*]] = call i1 @cond()
+; CHECK-NEXT:    [[AND_2:%.*]] = and i1 [[RANGE_CHECK]], [[FAKE_2]]
+; CHECK-NEXT:    br i1 [[AND_2]], label [[BACKEDGE]], label [[FAILED_2:%.*]]
+; CHECK:       backedge:
+; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], -1
+; CHECK-NEXT:    [[CANONICAL_IV_NEXT]] = add nuw nsw i32 [[CANONICAL_IV]], 1
+; CHECK-NEXT:    [[LOOP_COND:%.*]] = call i1 @cond()
+; CHECK-NEXT:    br i1 [[LOOP_COND]], label [[DONE:%.*]], label [[LOOP]]
+; CHECK:       done:
+; CHECK-NEXT:    [[IV_LCSSA3:%.*]] = phi i32 [ [[IV]], [[BACKEDGE]] ]
+; CHECK-NEXT:    ret i32 [[IV_LCSSA3]]
+; CHECK:       failed_1:
+; CHECK-NEXT:    ret i32 -1
+; CHECK:       failed_2:
+; CHECK-NEXT:    ret i32 -2
+; CHECK:       constant_check_failed:
+; CHECK-NEXT:    ret i32 -3
+;
+entry:
+  br label %loop
+
+loop:
+  %iv = phi i32 [%start, %entry], [%iv.next, %backedge]
+  %canonical_iv = phi i32 [0, %entry], [%canonical_iv.next, %backedge]
+  %constant_check = icmp ult i32 %canonical_iv, 65635
+  br i1 %constant_check, label %constant_check_passed, label %constant_check_failed
+
+constant_check_passed:
+  %zero_check = icmp ne i32 %iv, 0
+  %fake_1 = call i1 @cond()
+  %and_1 = and i1 %zero_check, %fake_1
+  br i1 %and_1, label %range_check_block, label %failed_1
+
+range_check_block:
+  %iv.minus.1 = add i32 %iv, -1
+  %range_check = icmp ult i32 %iv.minus.1, %len
+  %fake_2 = call i1 @cond()
+  %and_2 = and i1 %range_check, %fake_2
+  br i1 %and_2, label %backedge, label %failed_2
+
+backedge:
+  %iv.next = add i32 %iv, -1
+  %canonical_iv.next = add i32 %canonical_iv, 1
+  %loop_cond = call i1 @cond()
+  br i1 %loop_cond, label %done, label %loop
+
+done:
+  ret i32 %iv
+
+failed_1:
+  ret i32 -1
+
+failed_2:
+  ret i32 -2
+
+constant_check_failed:
+  ret i32 -3
+}


        


More information about the llvm-commits mailing list