1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s
4 define void @assume_false_to_unreachable1() {
5 ; CHECK-LABEL: @assume_false_to_unreachable1(
6 ; CHECK-NEXT: unreachable
8 call void @llvm.assume(i1 0)
13 define void @assume_undef_to_unreachable() {
14 ; CHECK-LABEL: @assume_undef_to_unreachable(
15 ; CHECK-NEXT: unreachable
17 call void @llvm.assume(i1 undef)
22 define i32 @speculate_block_with_assume_basic(i1 %c, i32 %x) {
23 ; CHECK-LABEL: @speculate_block_with_assume_basic(
25 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[C:%.*]], i32 1, i32 0
26 ; CHECK-NEXT: ret i32 [[SPEC_SELECT]]
29 br i1 %c, label %if, label %join
32 %cmp = icmp ne i32 %x, 0
33 call void @llvm.assume(i1 %cmp)
37 %phi = phi i32 [ 0, %entry ], [ 1, %if ]
41 define i32 @speculate_block_with_assume_extra_instr(i1 %c, i32 %x) {
42 ; CHECK-LABEL: @speculate_block_with_assume_extra_instr(
44 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[X:%.*]], 1
45 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[C:%.*]], i32 [[ADD]], i32 0
46 ; CHECK-NEXT: ret i32 [[SPEC_SELECT]]
49 br i1 %c, label %if, label %join
53 %cmp = icmp ne i32 %add, 0
54 call void @llvm.assume(i1 %cmp)
58 %phi = phi i32 [ 0, %entry ], [ %add, %if ]
62 ; We only allow speculating one instruction. Here %add and %add2 are used by
63 ; the assume, but not ephemeral, because they are also used by %phi.
64 define i32 @speculate_block_with_assume_extra_instrs_too_many(i1 %c, i32 %x) {
65 ; CHECK-LABEL: @speculate_block_with_assume_extra_instrs_too_many(
67 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[JOIN:%.*]]
69 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[X:%.*]], 1
70 ; CHECK-NEXT: [[ADD2:%.*]] = add i32 [[ADD]], 1
71 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[ADD2]], 0
72 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
73 ; CHECK-NEXT: br label [[JOIN]]
75 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[ADD2]], [[IF]] ]
76 ; CHECK-NEXT: ret i32 [[PHI]]
79 br i1 %c, label %if, label %join
83 %add2 = add i32 %add, 1
84 %cmp = icmp ne i32 %add2, 0
85 call void @llvm.assume(i1 %cmp)
89 %phi = phi i32 [ 0, %entry ], [ %add2, %if ]
93 define i32 @speculate_block_with_assume_extra_instrs_okay(i1 %c, i32 %x) {
94 ; CHECK-LABEL: @speculate_block_with_assume_extra_instrs_okay(
96 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[X:%.*]], 1
97 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[C:%.*]], i32 [[ADD]], i32 0
98 ; CHECK-NEXT: ret i32 [[SPEC_SELECT]]
101 br i1 %c, label %if, label %join
105 %add2 = add i32 %add, 1
106 %cmp = icmp ne i32 %add2, 0
107 call void @llvm.assume(i1 %cmp)
111 %phi = phi i32 [ 0, %entry ], [ %add, %if ]
115 define i32 @speculate_block_with_assume_operand_bundle(i1 %c, ptr %p) {
116 ; CHECK-LABEL: @speculate_block_with_assume_operand_bundle(
118 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[C:%.*]], i32 1, i32 0
119 ; CHECK-NEXT: ret i32 [[SPEC_SELECT]]
122 br i1 %c, label %if, label %join
125 call void @llvm.assume(i1 true) ["nonnull"(ptr %p)]
129 %phi = phi i32 [ 0, %entry ], [ 1, %if ]
133 define void @empty_block_with_assume(i1 %c, i32 %x) {
134 ; CHECK-LABEL: @empty_block_with_assume(
136 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
138 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X:%.*]], 0
139 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
140 ; CHECK-NEXT: br label [[JOIN:%.*]]
142 ; CHECK-NEXT: call void @dummy()
143 ; CHECK-NEXT: br label [[JOIN]]
145 ; CHECK-NEXT: ret void
148 br i1 %c, label %if, label %else
151 %cmp = icmp ne i32 %x, 0
152 call void @llvm.assume(i1 %cmp)
163 define void @not_empty_block_with_assume(i1 %c) {
164 ; CHECK-LABEL: @not_empty_block_with_assume(
166 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
168 ; CHECK-NEXT: [[X:%.*]] = call i32 @may_have_side_effect()
169 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X]], 0
170 ; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
171 ; CHECK-NEXT: br label [[JOIN:%.*]]
173 ; CHECK-NEXT: call void @dummy()
174 ; CHECK-NEXT: br label [[JOIN]]
176 ; CHECK-NEXT: ret void
179 br i1 %c, label %if, label %else
182 %x = call i32 @may_have_side_effect()
183 %cmp = icmp ne i32 %x, 0
184 call void @llvm.assume(i1 %cmp)
195 declare void @dummy()
196 declare i32 @may_have_side_effect()
197 declare void @llvm.assume(i1) nounwind