1; RUN: opt < %s -simplifycfg -S | FileCheck %s 2target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" 3 4declare i32 @__gxx_personality_v0(...) 5declare void @__cxa_call_unexpected(i8*) 6declare void @purefn() nounwind readnone 7declare i32 @read_only() nounwind readonly 8declare i32 @nounwind_fn() nounwind 9declare i32 @fn() 10 11 12; CHECK-LABEL: @f1( 13define i8* @f1() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 14entry: 15; CHECK: call void @llvm.trap() 16; CHECK: unreachable 17 %call = invoke noalias i8* undef() 18 to label %invoke.cont unwind label %lpad 19 20invoke.cont: 21 ret i8* %call 22 23lpad: 24 %0 = landingpad { i8*, i32 } 25 filter [0 x i8*] zeroinitializer 26 %1 = extractvalue { i8*, i32 } %0, 0 27 tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind 28 unreachable 29} 30 31; CHECK-LABEL: @f2( 32define i8* @f2() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 33entry: 34; CHECK: call void @llvm.trap() 35; CHECK: unreachable 36 %call = invoke noalias i8* null() 37 to label %invoke.cont unwind label %lpad 38 39invoke.cont: 40 ret i8* %call 41 42lpad: 43 %0 = landingpad { i8*, i32 } 44 filter [0 x i8*] zeroinitializer 45 %1 = extractvalue { i8*, i32 } %0, 0 46 tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind 47 unreachable 48} 49 50; CHECK-LABEL: @f2_no_null_opt( 51define i8* @f2_no_null_opt() nounwind uwtable ssp #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 52entry: 53; CHECK: invoke noalias i8* null() 54 %call = invoke noalias i8* null() 55 to label %invoke.cont unwind label %lpad 56 57; CHECK: invoke.cont: 58; CHECK: ret i8* %call 59invoke.cont: 60 ret i8* %call 61 62lpad: 63 %0 = landingpad { i8*, i32 } 64 filter [0 x i8*] zeroinitializer 65 %1 = extractvalue { i8*, i32 } %0, 0 66 tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind 67; CHECK: unreachable 68 unreachable 69} 70 71; CHECK-LABEL: @f3( 72define i32 @f3() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 73; CHECK-NEXT: entry 74entry: 75; CHECK-NEXT: ret i32 3 76 %call = invoke i32 @read_only() 77 to label %invoke.cont unwind label %lpad 78 79invoke.cont: 80 ret i32 3 81 82lpad: 83 %0 = landingpad { i8*, i32 } 84 filter [0 x i8*] zeroinitializer 85 %1 = extractvalue { i8*, i32 } %0, 0 86 tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind 87 unreachable 88} 89 90; CHECK-LABEL: @f4( 91define i32 @f4() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 92; CHECK-NEXT: entry 93entry: 94; CHECK-NEXT: call i32 @read_only() 95 %call = invoke i32 @read_only() 96 to label %invoke.cont unwind label %lpad 97 98invoke.cont: 99; CHECK-NEXT: ret i32 %call 100 ret i32 %call 101 102lpad: 103 %0 = landingpad { i8*, i32 } 104 filter [0 x i8*] zeroinitializer 105 %1 = extractvalue { i8*, i32 } %0, 0 106 tail call void @__cxa_call_unexpected(i8* %1) noreturn nounwind 107 unreachable 108} 109 110; CHECK-LABEL: @f5( 111define i32 @f5(i1 %cond, i8* %a, i8* %b) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 112entry: 113 br i1 %cond, label %x, label %y 114 115x: 116; CHECK: invoke i32 @fn() 117 %call = invoke i32 @fn() 118 to label %cont unwind label %lpad 119 120y: 121; CHECK: call i32 @nounwind_fn() 122 %call2 = invoke i32 @nounwind_fn() 123 to label %cont unwind label %lpad 124 125cont: 126; CHECK: phi i32 127; CHECK: ret i32 %phi 128 %phi = phi i32 [%call, %x], [%call2, %y] 129 ret i32 %phi 130 131lpad: 132; CHECK-NOT: phi 133 %phi2 = phi i8* [%a, %x], [%b, %y] 134 %0 = landingpad { i8*, i32 } 135 filter [0 x i8*] zeroinitializer 136; CHECK: __cxa_call_unexpected(i8* %a) 137 tail call void @__cxa_call_unexpected(i8* %phi2) noreturn nounwind 138 unreachable 139} 140 141; CHECK-LABEL: @f6( 142define void @f6() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 143entry: 144 invoke void @purefn() 145 to label %invoke.cont1 unwind label %lpad 146 147invoke.cont1: 148 %foo = invoke i32 @fn() 149 to label %invoke.cont2 unwind label %lpad 150 151invoke.cont2: 152 ret void 153 154lpad: 155; CHECK-NOT: phi 156 %tmp = phi i8* [ null, %invoke.cont1 ], [ null, %entry ] 157 landingpad { i8*, i32 } 158 cleanup 159 ret void 160} 161 162attributes #0 = { null_pointer_is_valid } 163