[llvm] bb4a955 - [Test] Add some IndVars test with swapped true/false branches
Max Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 12 04:08:24 PST 2022
Author: Max Kazantsev
Date: 2022-12-12T19:08:00+07:00
New Revision: bb4a955f27c13197f1dd1d604570bd764080b03c
URL: https://github.com/llvm/llvm-project/commit/bb4a955f27c13197f1dd1d604570bd764080b03c
DIFF: https://github.com/llvm/llvm-project/commit/bb4a955f27c13197f1dd1d604570bd764080b03c.diff
LOG: [Test] Add some IndVars test with swapped true/false branches
Just to make sure our transforms work correctly with them.
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 b43858ce1b88..541a4a5921cf 100644
--- a/llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll
+++ b/llvm/test/Transforms/IndVarSimplify/turn-to-invariant.ll
@@ -120,6 +120,67 @@ failed_2:
ret i32 -2
}
+; TODO: Same as test_litter_conditions, but swapped exit block branches.
+define i32 @test_litter_conditions_inverse(i32 %start, i32 %len) {
+; CHECK-LABEL: @test_litter_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: [[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 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: backedge:
+; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
+; CHECK-NEXT: [[LOOP_COND:%.*]] = call i1 @cond()
+; CHECK-NEXT: br i1 [[LOOP_COND]], label [[DONE:%.*]], label [[LOOP]]
+; CHECK: done:
+; CHECK-NEXT: [[IV_LCSSA2:%.*]] = phi i32 [ [[IV]], [[BACKEDGE]] ]
+; CHECK-NEXT: ret i32 [[IV_LCSSA2]]
+; CHECK: failed_1:
+; CHECK-NEXT: ret i32 -1
+; CHECK: failed_2:
+; CHECK-NEXT: ret i32 -2
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [%start, %entry], [%iv.next, %backedge]
+ %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 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
+
+backedge:
+ %iv.next = add i32 %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
+}
+
define i32 @test_litter_conditions_01(i32 %start, i32 %len) {
; CHECK-LABEL: @test_litter_conditions_01(
; CHECK-NEXT: entry:
@@ -176,6 +237,62 @@ failed_2:
ret i32 -2
}
+; TODO: Same as test_litter_conditions_01, but swapped exit block branches.
+define i32 @test_litter_conditions_01_inverse(i32 %start, i32 %len) {
+; CHECK-LABEL: @test_litter_conditions_01_inverse(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[START:%.*]], -1
+; 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: [[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: [[RANGE_CHECK3:%.*]] = icmp uge i32 [[TMP0]], [[LEN:%.*]]
+; CHECK-NEXT: br i1 [[RANGE_CHECK3]], label [[FAILED_2:%.*]], label [[BACKEDGE]]
+; CHECK: backedge:
+; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
+; CHECK-NEXT: [[LOOP_COND:%.*]] = call i1 @cond()
+; CHECK-NEXT: br i1 [[LOOP_COND]], label [[DONE:%.*]], label [[LOOP]]
+; CHECK: done:
+; CHECK-NEXT: [[IV_LCSSA2:%.*]] = phi i32 [ [[IV]], [[BACKEDGE]] ]
+; CHECK-NEXT: ret i32 [[IV_LCSSA2]]
+; CHECK: failed_1:
+; CHECK-NEXT: ret i32 -1
+; CHECK: failed_2:
+; CHECK-NEXT: ret i32 -2
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [%start, %entry], [%iv.next, %backedge]
+ %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 uge i32 %iv.minus.1, %len
+ br i1 %range_check, label %failed_2, label %backedge
+
+backedge:
+ %iv.next = add i32 %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
+}
; TODO: Simplified version 2 of test_litter_conditions.
define i32 @test_litter_conditions_02(i32 %start, i32 %len) {
@@ -234,6 +351,63 @@ failed_2:
ret i32 -2
}
+; TODO: Same as test_litter_conditions_02, but swapped exit block branches.
+define i32 @test_litter_conditions_02_inverse(i32 %start, i32 %len) {
+; CHECK-LABEL: @test_litter_conditions_02_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: 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: [[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: backedge:
+; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
+; CHECK-NEXT: [[LOOP_COND:%.*]] = call i1 @cond()
+; CHECK-NEXT: br i1 [[LOOP_COND]], label [[DONE:%.*]], label [[LOOP]]
+; CHECK: done:
+; CHECK-NEXT: [[IV_LCSSA2:%.*]] = phi i32 [ [[IV]], [[BACKEDGE]] ]
+; CHECK-NEXT: ret i32 [[IV_LCSSA2]]
+; CHECK: failed_1:
+; CHECK-NEXT: ret i32 -1
+; CHECK: failed_2:
+; CHECK-NEXT: ret i32 -2
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [%start, %entry], [%iv.next, %backedge]
+ %zero_check = icmp ne i32 %iv, 0
+ br i1 %zero_check, label %range_check_block, label %failed_1
+
+range_check_block:
+ %iv.minus.1 = add i32 %iv, -1
+ %range_check = 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
+
+backedge:
+ %iv.next = add i32 %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
+}
+
; TODO: Same as @test_litter_conditions, but all conditions are computed in
; header block. Make sure we infer fact from the right context.
; https://alive2.llvm.org/ce/z/JiD-Pw
@@ -297,6 +471,67 @@ failed_2:
ret i32 -2
}
+; TODO: Same as @test_litter_conditions_bad_context, but swapped exit block branches.
+define i32 @test_litter_conditions_bad_context_inverse(i32 %start, i32 %len) {
+; CHECK-LABEL: @test_litter_conditions_bad_context_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: [[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: [[FAKE_2:%.*]] = call i1 @cond()
+; CHECK-NEXT: [[AND_2:%.*]] = and i1 [[RANGE_CHECK]], [[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: backedge:
+; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
+; CHECK-NEXT: [[LOOP_COND:%.*]] = call i1 @cond()
+; CHECK-NEXT: br i1 [[LOOP_COND]], label [[DONE:%.*]], label [[LOOP]]
+; CHECK: done:
+; CHECK-NEXT: [[IV_LCSSA2:%.*]] = phi i32 [ [[IV]], [[BACKEDGE]] ]
+; CHECK-NEXT: ret i32 [[IV_LCSSA2]]
+; CHECK: failed_1:
+; CHECK-NEXT: ret i32 -1
+; CHECK: failed_2:
+; CHECK-NEXT: ret i32 -2
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [%start, %entry], [%iv.next, %backedge]
+ %zero_check = icmp ne i32 %iv, 0
+ %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
+ %fake_2 = call i1 @cond()
+ %and_2 = and i1 %range_check, %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
+
+backedge:
+ %iv.next = add i32 %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
+}
+
; TODO: This test is equivalent to @test_simple_case, with only
diff erence
; that both checks are merged together into one 'and' check. This
; should not prevent turning the range check into invariant.
@@ -344,3 +579,48 @@ done:
failed:
ret i32 -3
}
+
+; TODO: Same as test_and_conditions, but swapped exit block branches.
+define i32 @test_and_conditions_inverse(i32 %start, i32 %len) {
+; 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: [[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: backedge:
+; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], -1
+; CHECK-NEXT: [[LOOP_COND:%.*]] = call i1 @cond()
+; CHECK-NEXT: br i1 [[LOOP_COND]], label [[DONE:%.*]], label [[LOOP]]
+; CHECK: done:
+; CHECK-NEXT: [[IV_LCSSA1:%.*]] = phi i32 [ [[IV]], [[BACKEDGE]] ]
+; CHECK-NEXT: ret i32 [[IV_LCSSA1]]
+; CHECK: failed:
+; CHECK-NEXT: ret i32 -3
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i32 [%start, %entry], [%iv.next, %backedge]
+ %zero_check = icmp ne 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
+
+backedge:
+ %iv.next = add i32 %iv, -1
+ %loop_cond = call i1 @cond()
+ br i1 %loop_cond, label %done, label %loop
+
+done:
+ ret i32 %iv
+
+failed:
+ ret i32 -3
+}
More information about the llvm-commits
mailing list