[llvm] 5f24f89 - [Test] Update inverse test for turn-to-invariant to what they meant to be

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 26 01:09:09 PST 2022


Author: Max Kazantsev
Date: 2022-12-26T16:01:18+07:00
New Revision: 5f24f893cac7aaea292c70f8aa83b021499114be

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

LOG: [Test] Update inverse test for turn-to-invariant to what they meant to be

They were supposed to test inverted branches with OR condition, not AND.
Fixed this now.

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 54601d1f71df..6b992064dd92 100644
--- a/llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll
+++ b/llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll
@@ -5,7 +5,7 @@ declare i1 @cond()
 
 ; Range check here can be turned into invariant check.
 define i32 @test_simple_case(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_simple_case(
+; CHECK-LABEL: @test_simple_case(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[START:%.*]], -1
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
@@ -61,7 +61,7 @@ failed_2:
 ;       to replace it with invariant despite this fact.
 ;       https://alive2.llvm.org/ce/z/G4iW8c
 define i32 @test_litter_conditions(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_litter_conditions(
+; CHECK-LABEL: @test_litter_conditions(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
@@ -120,9 +120,10 @@ failed_2:
   ret i32 -2
 }
 
-; TODO: Same as test_litter_conditions, but swapped exit block branches.
+; TODO: Same as test_litter_conditions, but swapped exit block branches
+;       and exit condition expressed by OR. Still optimizable.
 define i32 @test_litter_conditions_inverse(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_litter_conditions_inverse(
+; CHECK-LABEL: @test_litter_conditions_inverse(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
@@ -133,10 +134,10 @@ define i32 @test_litter_conditions_inverse(i32 %start, i32 %len) {
 ; 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 uge i32 [[IV_MINUS_1]], [[LEN:%.*]]
+; CHECK-NEXT:    [[RANGE_CHECK_FAILED:%.*]] = icmp uge 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 [[FAILED_2:%.*]], label [[BACKEDGE]]
+; CHECK-NEXT:    [[OR_2:%.*]] = or i1 [[RANGE_CHECK_FAILED]], [[FAKE_2]]
+; CHECK-NEXT:    br i1 [[OR_2]], label [[FAILED_2:%.*]], label [[BACKEDGE]]
 ; CHECK:       backedge:
 ; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], -1
 ; CHECK-NEXT:    [[LOOP_COND:%.*]] = call i1 @cond()
@@ -161,10 +162,10 @@ loop:
 
 range_check_block:
   %iv.minus.1 = add i32 %iv, -1
-  %range_check = icmp uge i32 %iv.minus.1, %len
+  %range_check_failed = icmp uge i32 %iv.minus.1, %len
   %fake_2 = call i1 @cond()
-  %and_2 = and i1 %range_check, %fake_2
-  br i1 %and_2, label %failed_2, label %backedge
+  %or_2 = or i1 %range_check_failed, %fake_2
+  br i1 %or_2, label %failed_2, label %backedge
 
 backedge:
   %iv.next = add i32 %iv, -1
@@ -182,7 +183,7 @@ failed_2:
 }
 
 define i32 @test_litter_conditions_01(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_litter_conditions_01(
+; CHECK-LABEL: @test_litter_conditions_01(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[START:%.*]], -1
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
@@ -237,9 +238,10 @@ failed_2:
   ret i32 -2
 }
 
-; TODO: Same as test_litter_conditions_01, but swapped exit block branches.
+; TODO: Same as test_litter_conditions_01, but swapped exit block branches
+;       and condition expressed by OR. Still optimizable.
 define i32 @test_litter_conditions_01_inverse(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_litter_conditions_01_inverse(
+; CHECK-LABEL: @test_litter_conditions_01_inverse(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    [[TMP0:%.*]] = add i32 [[START:%.*]], -1
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
@@ -250,8 +252,8 @@ define i32 @test_litter_conditions_01_inverse(i32 %start, i32 %len) {
 ; 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:    [[RANGE_CHECK3:%.*]] = icmp uge i32 [[TMP0]], [[LEN:%.*]]
-; CHECK-NEXT:    br i1 [[RANGE_CHECK3]], label [[FAILED_2:%.*]], label [[BACKEDGE]]
+; CHECK-NEXT:    [[RANGE_CHECK_FAILED3:%.*]] = icmp uge i32 [[TMP0]], [[LEN:%.*]]
+; CHECK-NEXT:    br i1 [[RANGE_CHECK_FAILED3]], label [[FAILED_2:%.*]], label [[BACKEDGE]]
 ; CHECK:       backedge:
 ; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], -1
 ; CHECK-NEXT:    [[LOOP_COND:%.*]] = call i1 @cond()
@@ -276,8 +278,8 @@ loop:
 
 range_check_block:
   %iv.minus.1 = add i32 %iv, -1
-  %range_check = icmp uge i32 %iv.minus.1, %len
-  br i1 %range_check, label %failed_2, label %backedge
+  %range_check_failed = icmp uge i32 %iv.minus.1, %len
+  br i1 %range_check_failed, label %failed_2, label %backedge
 
 backedge:
   %iv.next = add i32 %iv, -1
@@ -296,7 +298,7 @@ failed_2:
 
 ; TODO: Simplified version 2 of test_litter_conditions.
 define i32 @test_litter_conditions_02(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_litter_conditions_02(
+; CHECK-LABEL: @test_litter_conditions_02(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
@@ -351,9 +353,10 @@ failed_2:
   ret i32 -2
 }
 
-; TODO: Same as test_litter_conditions_02, but swapped exit block branches.
+; TODO: Same as test_litter_conditions_02, but swapped exit block branches,
+;       and condition is expressed as OR. Still optimizable.
 define i32 @test_litter_conditions_02_inverse(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_litter_conditions_02_inverse(
+; CHECK-LABEL: @test_litter_conditions_02_inverse(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
@@ -362,10 +365,10 @@ define i32 @test_litter_conditions_02_inverse(i32 %start, i32 %len) {
 ; CHECK-NEXT:    br i1 [[ZERO_CHECK]], 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 uge i32 [[IV_MINUS_1]], [[LEN:%.*]]
+; CHECK-NEXT:    [[RANGE_CHECK_FAILED:%.*]] = icmp uge 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 [[FAILED_2:%.*]], label [[BACKEDGE]]
+; CHECK-NEXT:    [[OR_2:%.*]] = or i1 [[RANGE_CHECK_FAILED]], [[FAKE_2]]
+; CHECK-NEXT:    br i1 [[OR_2]], label [[FAILED_2:%.*]], label [[BACKEDGE]]
 ; CHECK:       backedge:
 ; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], -1
 ; CHECK-NEXT:    [[LOOP_COND:%.*]] = call i1 @cond()
@@ -388,10 +391,10 @@ loop:
 
 range_check_block:
   %iv.minus.1 = add i32 %iv, -1
-  %range_check = icmp uge i32 %iv.minus.1, %len
+  %range_check_failed = icmp uge i32 %iv.minus.1, %len
   %fake_2 = call i1 @cond()
-  %and_2 = and i1 %range_check, %fake_2
-  br i1 %and_2, label %failed_2, label %backedge
+  %or_2 = or i1 %range_check_failed, %fake_2
+  br i1 %or_2, label %failed_2, label %backedge
 
 backedge:
   %iv.next = add i32 %iv, -1
@@ -412,7 +415,7 @@ failed_2:
 ;       header block. Make sure we infer fact from the right context.
 ;       https://alive2.llvm.org/ce/z/JiD-Pw
 define i32 @test_litter_conditions_bad_context(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_litter_conditions_bad_context(
+; CHECK-LABEL: @test_litter_conditions_bad_context(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
@@ -471,9 +474,10 @@ failed_2:
   ret i32 -2
 }
 
-; TODO: Same as @test_litter_conditions_bad_context, but swapped exit block branches.
+; TODO: Same as @test_litter_conditions_bad_context, but swapped exit block branches,
+;       and conditions expressed as OR. Still optimizable.
 define i32 @test_litter_conditions_bad_context_inverse(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_litter_conditions_bad_context_inverse(
+; CHECK-LABEL: @test_litter_conditions_bad_context_inverse(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
@@ -482,12 +486,12 @@ define i32 @test_litter_conditions_bad_context_inverse(i32 %start, i32 %len) {
 ; CHECK-NEXT:    [[FAKE_1:%.*]] = call i1 @cond()
 ; CHECK-NEXT:    [[AND_1:%.*]] = and i1 [[ZERO_CHECK]], [[FAKE_1]]
 ; CHECK-NEXT:    [[IV_MINUS_1:%.*]] = add i32 [[IV]], -1
-; CHECK-NEXT:    [[RANGE_CHECK:%.*]] = icmp uge i32 [[IV_MINUS_1]], [[LEN:%.*]]
+; CHECK-NEXT:    [[RANGE_CHECK_FAILED:%.*]] = icmp uge i32 [[IV_MINUS_1]], [[LEN:%.*]]
 ; CHECK-NEXT:    [[FAKE_2:%.*]] = call i1 @cond()
-; CHECK-NEXT:    [[AND_2:%.*]] = and i1 [[RANGE_CHECK]], [[FAKE_2]]
+; CHECK-NEXT:    [[OR_2:%.*]] = or i1 [[RANGE_CHECK_FAILED]], [[FAKE_2]]
 ; CHECK-NEXT:    br i1 [[AND_1]], label [[RANGE_CHECK_BLOCK:%.*]], label [[FAILED_1:%.*]]
 ; CHECK:       range_check_block:
-; CHECK-NEXT:    br i1 [[AND_2]], label [[FAILED_2:%.*]], label [[BACKEDGE]]
+; CHECK-NEXT:    br i1 [[OR_2]], label [[FAILED_2:%.*]], label [[BACKEDGE]]
 ; CHECK:       backedge:
 ; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], -1
 ; CHECK-NEXT:    [[LOOP_COND:%.*]] = call i1 @cond()
@@ -509,13 +513,13 @@ loop:
   %fake_1 = call i1 @cond()
   %and_1 = and i1 %zero_check, %fake_1
   %iv.minus.1 = add i32 %iv, -1
-  %range_check = icmp uge i32 %iv.minus.1, %len
+  %range_check_failed = icmp uge i32 %iv.minus.1, %len
   %fake_2 = call i1 @cond()
-  %and_2 = and i1 %range_check, %fake_2
+  %or_2 = or i1 %range_check_failed, %fake_2
   br i1 %and_1, label %range_check_block, label %failed_1
 
 range_check_block:
-  br i1 %and_2, label %failed_2, label %backedge
+  br i1 %or_2, label %failed_2, label %backedge
 
 backedge:
   %iv.next = add i32 %iv, -1
@@ -537,7 +541,7 @@ failed_2:
 ;       should not prevent turning the range check into invariant.
 ;       https://alive2.llvm.org/ce/z/G-2ERB
 define i32 @test_and_conditions(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_and_conditions(
+; CHECK-LABEL: @test_and_conditions(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
@@ -580,18 +584,19 @@ failed:
   ret i32 -3
 }
 
-; TODO: Same as test_and_conditions, but swapped exit block branches.
+; TODO: Same as test_and_conditions, but swapped exit block branches,
+;       and condition is expressed as OR. Still optimizable.
 define i32 @test_and_conditions_inverse(i32 %start, i32 %len) {
-; CHECK-LABEL: define {{[^@]+}}@test_and_conditions_inverse(
+; CHECK-LABEL: @test_and_conditions_inverse(
 ; CHECK-NEXT:  entry:
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
 ; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ [[START:%.*]], [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT:    [[ZERO_CHECK:%.*]] = icmp ne i32 [[IV]], 0
+; CHECK-NEXT:    [[ZERO_CHECK_FAILED:%.*]] = icmp eq i32 [[IV]], 0
 ; CHECK-NEXT:    [[IV_MINUS_1:%.*]] = add i32 [[IV]], -1
-; CHECK-NEXT:    [[RANGE_CHECK:%.*]] = icmp uge i32 [[IV_MINUS_1]], [[LEN:%.*]]
-; CHECK-NEXT:    [[BOTH_CHECKS:%.*]] = and i1 [[ZERO_CHECK]], [[RANGE_CHECK]]
-; CHECK-NEXT:    br i1 [[BOTH_CHECKS]], label [[FAILED:%.*]], label [[BACKEDGE]]
+; CHECK-NEXT:    [[RANGE_CHECK_FAILED:%.*]] = icmp uge i32 [[IV_MINUS_1]], [[LEN:%.*]]
+; CHECK-NEXT:    [[EITHER_CHECK:%.*]] = or i1 [[ZERO_CHECK_FAILED]], [[RANGE_CHECK_FAILED]]
+; CHECK-NEXT:    br i1 [[EITHER_CHECK]], label [[FAILED:%.*]], label [[BACKEDGE]]
 ; CHECK:       backedge:
 ; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], -1
 ; CHECK-NEXT:    [[LOOP_COND:%.*]] = call i1 @cond()
@@ -607,11 +612,11 @@ entry:
 
 loop:
   %iv = phi i32 [%start, %entry], [%iv.next, %backedge]
-  %zero_check = icmp ne i32 %iv, 0
+  %zero_check_failed = icmp eq i32 %iv, 0
   %iv.minus.1 = add i32 %iv, -1
-  %range_check = icmp uge i32 %iv.minus.1, %len
-  %both_checks = and i1 %zero_check, %range_check
-  br i1 %both_checks, label %failed, label %backedge
+  %range_check_failed = icmp uge i32 %iv.minus.1, %len
+  %either_check = or i1 %zero_check_failed, %range_check_failed
+  br i1 %either_check, label %failed, label %backedge
 
 backedge:
   %iv.next = add i32 %iv, -1


        


More information about the llvm-commits mailing list