Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -simplifycfg -S | FileCheck %s |
| 2 | target 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 | |
| 4 | declare i32 @__gxx_personality_v0(...) |
| 5 | declare void @__cxa_call_unexpected(i8*) |
| 6 | declare void @purefn() nounwind readnone |
| 7 | declare i32 @read_only() nounwind readonly |
| 8 | declare i32 @nounwind_fn() nounwind |
| 9 | declare i32 @fn() |
| 10 | |
| 11 | |
| 12 | ; CHECK-LABEL: @f1( |
| 13 | define i8* @f1() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { |
| 14 | entry: |
| 15 | ; CHECK: call void @llvm.trap() |
| 16 | ; CHECK: unreachable |
| 17 | %call = invoke noalias i8* undef() |
| 18 | to label %invoke.cont unwind label %lpad |
| 19 | |
| 20 | invoke.cont: |
| 21 | ret i8* %call |
| 22 | |
| 23 | lpad: |
| 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( |
| 32 | define i8* @f2() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { |
| 33 | entry: |
| 34 | ; CHECK: call void @llvm.trap() |
| 35 | ; CHECK: unreachable |
| 36 | %call = invoke noalias i8* null() |
| 37 | to label %invoke.cont unwind label %lpad |
| 38 | |
| 39 | invoke.cont: |
| 40 | ret i8* %call |
| 41 | |
| 42 | lpad: |
| 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( |
| 51 | define i8* @f2_no_null_opt() nounwind uwtable ssp #0 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { |
| 52 | entry: |
| 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 |
| 59 | invoke.cont: |
| 60 | ret i8* %call |
| 61 | |
| 62 | lpad: |
| 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( |
| 72 | define i32 @f3() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { |
| 73 | ; CHECK-NEXT: entry |
| 74 | entry: |
| 75 | ; CHECK-NEXT: ret i32 3 |
| 76 | %call = invoke i32 @read_only() |
| 77 | to label %invoke.cont unwind label %lpad |
| 78 | |
| 79 | invoke.cont: |
| 80 | ret i32 3 |
| 81 | |
| 82 | lpad: |
| 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( |
| 91 | define i32 @f4() nounwind uwtable ssp personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { |
| 92 | ; CHECK-NEXT: entry |
| 93 | entry: |
| 94 | ; CHECK-NEXT: call i32 @read_only() |
| 95 | %call = invoke i32 @read_only() |
| 96 | to label %invoke.cont unwind label %lpad |
| 97 | |
| 98 | invoke.cont: |
| 99 | ; CHECK-NEXT: ret i32 %call |
| 100 | ret i32 %call |
| 101 | |
| 102 | lpad: |
| 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( |
| 111 | define i32 @f5(i1 %cond, i8* %a, i8* %b) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { |
| 112 | entry: |
| 113 | br i1 %cond, label %x, label %y |
| 114 | |
| 115 | x: |
| 116 | ; CHECK: invoke i32 @fn() |
| 117 | %call = invoke i32 @fn() |
| 118 | to label %cont unwind label %lpad |
| 119 | |
| 120 | y: |
| 121 | ; CHECK: call i32 @nounwind_fn() |
| 122 | %call2 = invoke i32 @nounwind_fn() |
| 123 | to label %cont unwind label %lpad |
| 124 | |
| 125 | cont: |
| 126 | ; CHECK: phi i32 |
| 127 | ; CHECK: ret i32 %phi |
| 128 | %phi = phi i32 [%call, %x], [%call2, %y] |
| 129 | ret i32 %phi |
| 130 | |
| 131 | lpad: |
| 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( |
| 142 | define void @f6() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { |
| 143 | entry: |
| 144 | invoke void @purefn() |
| 145 | to label %invoke.cont1 unwind label %lpad |
| 146 | |
| 147 | invoke.cont1: |
| 148 | %foo = invoke i32 @fn() |
| 149 | to label %invoke.cont2 unwind label %lpad |
| 150 | |
| 151 | invoke.cont2: |
| 152 | ret void |
| 153 | |
| 154 | lpad: |
| 155 | ; CHECK-NOT: phi |
| 156 | %tmp = phi i8* [ null, %invoke.cont1 ], [ null, %entry ] |
| 157 | landingpad { i8*, i32 } |
| 158 | cleanup |
| 159 | ret void |
| 160 | } |
| 161 | |
| 162 | attributes #0 = { "null-pointer-is-valid"="true" } |