2021-04-28 02:28:53 +08:00
|
|
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
2020-12-18 01:13:03 +08:00
|
|
|
; RUN: opt %s -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s
|
2019-04-17 12:52:47 +08:00
|
|
|
; Check for when one branch implies the value of a successors conditional and
|
|
|
|
; it's not simply the same conditional repeated.
|
|
|
|
|
|
|
|
define void @test(i32 %length.i, i32 %i) {
|
2021-04-28 02:28:53 +08:00
|
|
|
; CHECK-LABEL: @test(
|
|
|
|
; CHECK-NEXT: [[IPLUS1:%.*]] = add nsw i32 [[I:%.*]], 1
|
|
|
|
; CHECK-NEXT: [[VAR29:%.*]] = icmp slt i32 [[IPLUS1]], [[LENGTH_I:%.*]]
|
|
|
|
; CHECK-NEXT: br i1 [[VAR29]], label [[IN_BOUNDS:%.*]], label [[OUT_OF_BOUNDS:%.*]]
|
|
|
|
; CHECK: in_bounds:
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK: out_of_bounds:
|
|
|
|
; CHECK-NEXT: call void @foo(i64 0)
|
|
|
|
; CHECK-NEXT: unreachable
|
|
|
|
;
|
2019-04-17 12:52:47 +08:00
|
|
|
%iplus1 = add nsw i32 %i, 1
|
|
|
|
%var29 = icmp slt i32 %iplus1, %length.i
|
|
|
|
br i1 %var29, label %next, label %out_of_bounds
|
|
|
|
|
|
|
|
next:
|
|
|
|
%var30 = icmp slt i32 %i, %length.i
|
|
|
|
br i1 %var30, label %in_bounds, label %out_of_bounds2
|
|
|
|
|
|
|
|
in_bounds:
|
|
|
|
ret void
|
|
|
|
|
|
|
|
out_of_bounds:
|
|
|
|
call void @foo(i64 0)
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
out_of_bounds2:
|
|
|
|
call void @foo(i64 1)
|
|
|
|
unreachable
|
|
|
|
}
|
|
|
|
|
|
|
|
; If the add is not nsw, it's not safe to use the fact about i+1 to imply the
|
|
|
|
; i condition since it could have overflowed.
|
|
|
|
define void @test_neg(i32 %length.i, i32 %i) {
|
2021-04-28 02:28:53 +08:00
|
|
|
; CHECK-LABEL: @test_neg(
|
|
|
|
; CHECK-NEXT: [[IPLUS1:%.*]] = add i32 [[I:%.*]], 1
|
|
|
|
; CHECK-NEXT: [[VAR29:%.*]] = icmp slt i32 [[IPLUS1]], [[LENGTH_I:%.*]]
|
|
|
|
; CHECK-NEXT: br i1 [[VAR29]], label [[NEXT:%.*]], label [[OUT_OF_BOUNDS:%.*]]
|
|
|
|
; CHECK: next:
|
|
|
|
; CHECK-NEXT: [[VAR30:%.*]] = icmp slt i32 [[I]], [[LENGTH_I]]
|
|
|
|
; CHECK-NEXT: br i1 [[VAR30]], label [[IN_BOUNDS:%.*]], label [[OUT_OF_BOUNDS2:%.*]]
|
|
|
|
; CHECK: in_bounds:
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK: out_of_bounds:
|
|
|
|
; CHECK-NEXT: call void @foo(i64 0)
|
|
|
|
; CHECK-NEXT: unreachable
|
|
|
|
; CHECK: out_of_bounds2:
|
|
|
|
; CHECK-NEXT: call void @foo(i64 1)
|
|
|
|
; CHECK-NEXT: unreachable
|
|
|
|
;
|
2019-04-17 12:52:47 +08:00
|
|
|
%iplus1 = add i32 %i, 1
|
|
|
|
%var29 = icmp slt i32 %iplus1, %length.i
|
|
|
|
br i1 %var29, label %next, label %out_of_bounds
|
|
|
|
|
|
|
|
next:
|
|
|
|
%var30 = icmp slt i32 %i, %length.i
|
|
|
|
br i1 %var30, label %in_bounds, label %out_of_bounds2
|
|
|
|
|
|
|
|
in_bounds:
|
|
|
|
ret void
|
|
|
|
|
|
|
|
out_of_bounds:
|
|
|
|
call void @foo(i64 0)
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
out_of_bounds2:
|
|
|
|
call void @foo(i64 1)
|
|
|
|
unreachable
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
define void @test2(i32 %length.i, i32 %i) {
|
2021-04-28 02:28:53 +08:00
|
|
|
; CHECK-LABEL: @test2(
|
|
|
|
; CHECK-NEXT: [[IPLUS100:%.*]] = add nsw i32 [[I:%.*]], 100
|
|
|
|
; CHECK-NEXT: [[VAR29:%.*]] = icmp slt i32 [[IPLUS100]], [[LENGTH_I:%.*]]
|
|
|
|
; CHECK-NEXT: br i1 [[VAR29]], label [[IN_BOUNDS:%.*]], label [[OUT_OF_BOUNDS:%.*]]
|
|
|
|
; CHECK: in_bounds:
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK: out_of_bounds:
|
|
|
|
; CHECK-NEXT: call void @foo(i64 0)
|
|
|
|
; CHECK-NEXT: unreachable
|
|
|
|
;
|
2019-04-17 12:52:47 +08:00
|
|
|
%iplus100 = add nsw i32 %i, 100
|
|
|
|
%var29 = icmp slt i32 %iplus100, %length.i
|
|
|
|
br i1 %var29, label %next, label %out_of_bounds
|
|
|
|
|
|
|
|
next:
|
|
|
|
%var30 = icmp slt i32 %i, %length.i
|
|
|
|
br i1 %var30, label %in_bounds, label %out_of_bounds2
|
|
|
|
|
|
|
|
in_bounds:
|
|
|
|
ret void
|
|
|
|
|
|
|
|
out_of_bounds:
|
|
|
|
call void @foo(i64 0)
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
out_of_bounds2:
|
|
|
|
call void @foo(i64 1)
|
|
|
|
unreachable
|
|
|
|
}
|
|
|
|
|
|
|
|
declare void @foo(i64)
|
|
|
|
|