; 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:%.*]]
; 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:
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:
; 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()
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
}
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:%.*]]
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:%.*]]
; 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()
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
; 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:
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:
; 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()
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
; 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:
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:
; 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()
%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
; 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:
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()
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