1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
4 define void @test1(i1 %C, i1* %BP) {
7 ; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[C:%.*]], true
8 ; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
12 br i1 %C, label %T, label %F
20 define void @test2() personality i32 (...)* @__gxx_personality_v0 {
21 ; CHECK-LABEL: @test2(
23 ; CHECK-NEXT: call void @test2()
24 ; CHECK-NEXT: ret void
28 to label %N unwind label %U
30 %res = landingpad { i8* }
37 declare i32 @__gxx_personality_v0(...)
39 define i32 @test3(i32 %v) {
40 ; CHECK-LABEL: @test3(
42 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[V:%.*]], 2
43 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[COND]], i32 2, i32 1
44 ; CHECK-NEXT: ret i32 [[SPEC_SELECT]]
47 switch i32 %v, label %default [
60 ;; We can either convert the following control-flow to a select or remove the
61 ;; unreachable control flow because of the undef store of null. Make sure we do
64 define void @test5(i1 %cond, i8* %ptr) {
65 ; CHECK-LABEL: @test5(
67 ; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[COND:%.*]], true
68 ; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
69 ; CHECK-NEXT: store i8 2, i8* [[PTR:%.*]], align 8
70 ; CHECK-NEXT: ret void
74 br i1 %cond, label %bb1, label %bb3
83 %ptr.2 = phi i8* [ %ptr, %bb3 ], [ null, %bb1 ]
84 store i8 2, i8* %ptr.2, align 8
88 define void @test5_no_null_opt(i1 %cond, i8* %ptr) #0 {
89 ; CHECK-LABEL: @test5_no_null_opt(
91 ; CHECK-NEXT: [[DOTPTR:%.*]] = select i1 [[COND:%.*]], i8* null, i8* [[PTR:%.*]]
92 ; CHECK-NEXT: store i8 2, i8* [[DOTPTR]], align 8
93 ; CHECK-NEXT: ret void
97 br i1 %cond, label %bb1, label %bb3
106 %ptr.2 = phi i8* [ %ptr, %bb3 ], [ null, %bb1 ]
107 store i8 2, i8* %ptr.2, align 8
111 define void @test6(i1 %cond, i8* %ptr) {
112 ; CHECK-LABEL: @test6(
114 ; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[COND:%.*]], true
115 ; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
116 ; CHECK-NEXT: store i8 2, i8* [[PTR:%.*]], align 8
117 ; CHECK-NEXT: ret void
120 br i1 %cond, label %bb1, label %bb2
126 %ptr.2 = phi i8* [ %ptr, %entry ], [ null, %bb1 ]
127 store i8 2, i8* %ptr.2, align 8
131 define void @test6_no_null_opt(i1 %cond, i8* %ptr) #0 {
132 ; CHECK-LABEL: @test6_no_null_opt(
134 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[COND:%.*]], i8* null, i8* [[PTR:%.*]]
135 ; CHECK-NEXT: store i8 2, i8* [[SPEC_SELECT]], align 8
136 ; CHECK-NEXT: ret void
139 br i1 %cond, label %bb1, label %bb2
145 %ptr.2 = phi i8* [ %ptr, %entry ], [ null, %bb1 ]
146 store i8 2, i8* %ptr.2, align 8
151 define i32 @test7(i1 %X) {
152 ; CHECK-LABEL: @test7(
154 ; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true
155 ; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
156 ; CHECK-NEXT: ret i32 0
159 br i1 %X, label %if, label %else
166 %phi = phi i32 [ 0, %entry ], [ 1, %if ]
170 define void @test8(i1 %X, void ()* %Y) {
171 ; CHECK-LABEL: @test8(
173 ; CHECK-NEXT: [[TMP0:%.*]] = xor i1 [[X:%.*]], true
174 ; CHECK-NEXT: call void @llvm.assume(i1 [[TMP0]])
175 ; CHECK-NEXT: call void [[Y:%.*]]()
176 ; CHECK-NEXT: ret void
179 br i1 %X, label %if, label %else
185 %phi = phi void ()* [ %Y, %entry ], [ null, %if ]
190 define void @test8_no_null_opt(i1 %X, void ()* %Y) #0 {
191 ; CHECK-LABEL: @test8_no_null_opt(
193 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[X:%.*]], void ()* null, void ()* [[Y:%.*]]
194 ; CHECK-NEXT: call void [[SPEC_SELECT]]()
195 ; CHECK-NEXT: ret void
198 br i1 %X, label %if, label %else
204 %phi = phi void ()* [ %Y, %entry ], [ null, %if ]
209 attributes #0 = { "null-pointer-is-valid"="true" }