Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 2 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
Davide Italiano | 16284df | 2016-07-07 21:14:36 +0000 | [diff] [blame] | 3 | ; RUN: opt < %s -passes=instsimplify -S | FileCheck %s |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 4 | |
| 5 | declare {i8, i1} @llvm.uadd.with.overflow.i8(i8 %a, i8 %b) |
Craig Topper | ae292aa | 2017-05-23 18:42:58 +0000 | [diff] [blame] | 6 | declare {i8, i1} @llvm.sadd.with.overflow.i8(i8 %a, i8 %b) |
David Majnemer | 1503258 | 2015-05-22 03:56:46 +0000 | [diff] [blame] | 7 | declare {i8, i1} @llvm.usub.with.overflow.i8(i8 %a, i8 %b) |
| 8 | declare {i8, i1} @llvm.ssub.with.overflow.i8(i8 %a, i8 %b) |
| 9 | declare {i8, i1} @llvm.umul.with.overflow.i8(i8 %a, i8 %b) |
Craig Topper | ae292aa | 2017-05-23 18:42:58 +0000 | [diff] [blame] | 10 | declare {i8, i1} @llvm.smul.with.overflow.i8(i8 %a, i8 %b) |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 11 | |
| 12 | define i1 @test_uadd1() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 13 | ; CHECK-LABEL: @test_uadd1( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 14 | ; CHECK-NEXT: ret i1 true |
| 15 | ; |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 16 | %x = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 254, i8 3) |
| 17 | %overflow = extractvalue {i8, i1} %x, 1 |
| 18 | ret i1 %overflow |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | define i8 @test_uadd2() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 22 | ; CHECK-LABEL: @test_uadd2( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 23 | ; CHECK-NEXT: ret i8 42 |
| 24 | ; |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 25 | %x = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 254, i8 44) |
| 26 | %result = extractvalue {i8, i1} %x, 0 |
| 27 | ret i8 %result |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Craig Topper | ae292aa | 2017-05-23 18:42:58 +0000 | [diff] [blame] | 30 | define {i8, i1} @test_uadd3(i8 %v) { |
| 31 | ; CHECK-LABEL: @test_uadd3( |
| 32 | ; CHECK-NEXT: ret { i8, i1 } undef |
| 33 | ; |
| 34 | %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %v, i8 undef) |
| 35 | ret {i8, i1} %result |
| 36 | } |
| 37 | |
Craig Topper | 77e07cc | 2017-05-24 17:05:28 +0000 | [diff] [blame] | 38 | define {i8, i1} @test_uadd4(i8 %v) { |
| 39 | ; CHECK-LABEL: @test_uadd4( |
| 40 | ; CHECK-NEXT: ret { i8, i1 } undef |
| 41 | ; |
| 42 | %result = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 undef, i8 %v) |
| 43 | ret {i8, i1} %result |
| 44 | } |
| 45 | |
Craig Topper | ae292aa | 2017-05-23 18:42:58 +0000 | [diff] [blame] | 46 | define i1 @test_sadd1() { |
| 47 | ; CHECK-LABEL: @test_sadd1( |
| 48 | ; CHECK-NEXT: ret i1 true |
| 49 | ; |
| 50 | %x = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 126, i8 3) |
| 51 | %overflow = extractvalue {i8, i1} %x, 1 |
| 52 | ret i1 %overflow |
| 53 | } |
| 54 | |
| 55 | define i8 @test_sadd2() { |
| 56 | ; CHECK-LABEL: @test_sadd2( |
| 57 | ; CHECK-NEXT: ret i8 -86 |
| 58 | ; |
| 59 | %x = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 126, i8 44) |
| 60 | %result = extractvalue {i8, i1} %x, 0 |
| 61 | ret i8 %result |
| 62 | } |
| 63 | |
| 64 | define {i8, i1} @test_sadd3(i8 %v) { |
| 65 | ; CHECK-LABEL: @test_sadd3( |
| 66 | ; CHECK-NEXT: ret { i8, i1 } undef |
| 67 | ; |
| 68 | %result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 %v, i8 undef) |
| 69 | ret {i8, i1} %result |
| 70 | } |
| 71 | |
Craig Topper | 77e07cc | 2017-05-24 17:05:28 +0000 | [diff] [blame] | 72 | define {i8, i1} @test_sadd4(i8 %v) { |
| 73 | ; CHECK-LABEL: @test_sadd4( |
| 74 | ; CHECK-NEXT: ret { i8, i1 } undef |
| 75 | ; |
| 76 | %result = call {i8, i1} @llvm.sadd.with.overflow.i8(i8 undef, i8 %v) |
| 77 | ret {i8, i1} %result |
| 78 | } |
| 79 | |
David Majnemer | 1503258 | 2015-05-22 03:56:46 +0000 | [diff] [blame] | 80 | define {i8, i1} @test_usub1(i8 %V) { |
| 81 | ; CHECK-LABEL: @test_usub1( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 82 | ; CHECK-NEXT: ret { i8, i1 } zeroinitializer |
| 83 | ; |
David Majnemer | 1503258 | 2015-05-22 03:56:46 +0000 | [diff] [blame] | 84 | %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 %V, i8 %V) |
| 85 | ret {i8, i1} %x |
David Majnemer | 1503258 | 2015-05-22 03:56:46 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Craig Topper | ae292aa | 2017-05-23 18:42:58 +0000 | [diff] [blame] | 88 | define {i8, i1} @test_usub2(i8 %V) { |
| 89 | ; CHECK-LABEL: @test_usub2( |
| 90 | ; CHECK-NEXT: ret { i8, i1 } undef |
| 91 | ; |
| 92 | %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 %V, i8 undef) |
| 93 | ret {i8, i1} %x |
| 94 | } |
| 95 | |
| 96 | define {i8, i1} @test_usub3(i8 %V) { |
| 97 | ; CHECK-LABEL: @test_usub3( |
| 98 | ; CHECK-NEXT: ret { i8, i1 } undef |
| 99 | ; |
| 100 | %x = call {i8, i1} @llvm.usub.with.overflow.i8(i8 undef, i8 %V) |
| 101 | ret {i8, i1} %x |
| 102 | } |
| 103 | |
David Majnemer | 1503258 | 2015-05-22 03:56:46 +0000 | [diff] [blame] | 104 | define {i8, i1} @test_ssub1(i8 %V) { |
| 105 | ; CHECK-LABEL: @test_ssub1( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 106 | ; CHECK-NEXT: ret { i8, i1 } zeroinitializer |
| 107 | ; |
David Majnemer | 1503258 | 2015-05-22 03:56:46 +0000 | [diff] [blame] | 108 | %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 %V, i8 %V) |
| 109 | ret {i8, i1} %x |
David Majnemer | 1503258 | 2015-05-22 03:56:46 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Craig Topper | ae292aa | 2017-05-23 18:42:58 +0000 | [diff] [blame] | 112 | define {i8, i1} @test_ssub2(i8 %V) { |
| 113 | ; CHECK-LABEL: @test_ssub2( |
| 114 | ; CHECK-NEXT: ret { i8, i1 } undef |
| 115 | ; |
| 116 | %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 %V, i8 undef) |
| 117 | ret {i8, i1} %x |
| 118 | } |
| 119 | |
| 120 | define {i8, i1} @test_ssub3(i8 %V) { |
| 121 | ; CHECK-LABEL: @test_ssub3( |
| 122 | ; CHECK-NEXT: ret { i8, i1 } undef |
| 123 | ; |
| 124 | %x = call {i8, i1} @llvm.ssub.with.overflow.i8(i8 undef, i8 %V) |
| 125 | ret {i8, i1} %x |
| 126 | } |
| 127 | |
David Majnemer | 1503258 | 2015-05-22 03:56:46 +0000 | [diff] [blame] | 128 | define {i8, i1} @test_umul1(i8 %V) { |
| 129 | ; CHECK-LABEL: @test_umul1( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 130 | ; CHECK-NEXT: ret { i8, i1 } zeroinitializer |
| 131 | ; |
David Majnemer | 1503258 | 2015-05-22 03:56:46 +0000 | [diff] [blame] | 132 | %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 %V, i8 0) |
| 133 | ret {i8, i1} %x |
David Majnemer | 1503258 | 2015-05-22 03:56:46 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Craig Topper | ae292aa | 2017-05-23 18:42:58 +0000 | [diff] [blame] | 136 | define {i8, i1} @test_umul2(i8 %V) { |
| 137 | ; CHECK-LABEL: @test_umul2( |
| 138 | ; CHECK-NEXT: ret { i8, i1 } zeroinitializer |
| 139 | ; |
| 140 | %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 %V, i8 undef) |
| 141 | ret {i8, i1} %x |
| 142 | } |
| 143 | |
Craig Topper | 77e07cc | 2017-05-24 17:05:28 +0000 | [diff] [blame] | 144 | define {i8, i1} @test_umul3(i8 %V) { |
| 145 | ; CHECK-LABEL: @test_umul3( |
| 146 | ; CHECK-NEXT: ret { i8, i1 } zeroinitializer |
| 147 | ; |
| 148 | %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 0, i8 %V) |
| 149 | ret {i8, i1} %x |
| 150 | } |
| 151 | |
| 152 | define {i8, i1} @test_umul4(i8 %V) { |
| 153 | ; CHECK-LABEL: @test_umul4( |
| 154 | ; CHECK-NEXT: ret { i8, i1 } zeroinitializer |
| 155 | ; |
| 156 | %x = call {i8, i1} @llvm.umul.with.overflow.i8(i8 undef, i8 %V) |
| 157 | ret {i8, i1} %x |
| 158 | } |
| 159 | |
Craig Topper | ae292aa | 2017-05-23 18:42:58 +0000 | [diff] [blame] | 160 | define {i8, i1} @test_smul1(i8 %V) { |
| 161 | ; CHECK-LABEL: @test_smul1( |
| 162 | ; CHECK-NEXT: ret { i8, i1 } zeroinitializer |
| 163 | ; |
| 164 | %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 %V, i8 0) |
| 165 | ret {i8, i1} %x |
| 166 | } |
| 167 | |
| 168 | define {i8, i1} @test_smul2(i8 %V) { |
| 169 | ; CHECK-LABEL: @test_smul2( |
| 170 | ; CHECK-NEXT: ret { i8, i1 } zeroinitializer |
| 171 | ; |
| 172 | %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 %V, i8 undef) |
| 173 | ret {i8, i1} %x |
| 174 | } |
| 175 | |
Craig Topper | 77e07cc | 2017-05-24 17:05:28 +0000 | [diff] [blame] | 176 | define {i8, i1} @test_smul3(i8 %V) { |
| 177 | ; CHECK-LABEL: @test_smul3( |
| 178 | ; CHECK-NEXT: ret { i8, i1 } zeroinitializer |
| 179 | ; |
| 180 | %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 0, i8 %V) |
| 181 | ret {i8, i1} %x |
| 182 | } |
| 183 | |
| 184 | define {i8, i1} @test_smul4(i8 %V) { |
| 185 | ; CHECK-LABEL: @test_smul4( |
| 186 | ; CHECK-NEXT: ret { i8, i1 } zeroinitializer |
| 187 | ; |
| 188 | %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 undef, i8 %V) |
| 189 | ret {i8, i1} %x |
| 190 | } |
| 191 | |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 192 | declare i256 @llvm.cttz.i256(i256 %src, i1 %is_zero_undef) |
| 193 | |
| 194 | define i256 @test_cttz() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 195 | ; CHECK-LABEL: @test_cttz( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 196 | ; CHECK-NEXT: ret i256 1 |
| 197 | ; |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 198 | %x = call i256 @llvm.cttz.i256(i256 10, i1 false) |
| 199 | ret i256 %x |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Craig Topper | 36fa2f0 | 2017-06-03 18:50:26 +0000 | [diff] [blame] | 202 | declare <2 x i256> @llvm.cttz.v2i256(<2 x i256> %src, i1 %is_zero_undef) |
| 203 | |
| 204 | define <2 x i256> @test_cttz_vec() { |
| 205 | ; CHECK-LABEL: @test_cttz_vec( |
Craig Topper | 7c553ed | 2017-06-03 18:50:29 +0000 | [diff] [blame] | 206 | ; CHECK-NEXT: ret <2 x i256> <i256 1, i256 1> |
Craig Topper | 36fa2f0 | 2017-06-03 18:50:26 +0000 | [diff] [blame] | 207 | ; |
| 208 | %x = call <2 x i256> @llvm.cttz.v2i256(<2 x i256> <i256 10, i256 10>, i1 false) |
| 209 | ret <2 x i256> %x |
| 210 | } |
| 211 | |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 212 | declare i256 @llvm.ctpop.i256(i256 %src) |
| 213 | |
| 214 | define i256 @test_ctpop() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 215 | ; CHECK-LABEL: @test_ctpop( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 216 | ; CHECK-NEXT: ret i256 2 |
| 217 | ; |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 218 | %x = call i256 @llvm.ctpop.i256(i256 10) |
| 219 | ret i256 %x |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | ; Test a non-intrinsic that we know about as a library call. |
| 223 | declare float @fabs(float %x) |
| 224 | |
| 225 | define float @test_fabs_libcall() { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 226 | ; CHECK-LABEL: @test_fabs_libcall( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 227 | ; CHECK-NEXT: [[X:%.*]] = call float @fabs(float -4.200000e+01) |
| 228 | ; CHECK-NEXT: ret float 4.200000e+01 |
| 229 | ; |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 230 | |
| 231 | %x = call float @fabs(float -42.0) |
| 232 | ; This is still a real function call, so instsimplify won't nuke it -- other |
| 233 | ; passes have to do that. |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 234 | |
| 235 | ret float %x |
Chandler Carruth | f618215 | 2012-12-28 14:23:29 +0000 | [diff] [blame] | 236 | } |
Michael Ilseman | 5485729 | 2013-02-07 19:26:05 +0000 | [diff] [blame] | 237 | |
| 238 | |
| 239 | declare float @llvm.fabs.f32(float) nounwind readnone |
| 240 | declare float @llvm.floor.f32(float) nounwind readnone |
| 241 | declare float @llvm.ceil.f32(float) nounwind readnone |
| 242 | declare float @llvm.trunc.f32(float) nounwind readnone |
| 243 | declare float @llvm.rint.f32(float) nounwind readnone |
| 244 | declare float @llvm.nearbyint.f32(float) nounwind readnone |
| 245 | |
| 246 | ; Test idempotent intrinsics |
| 247 | define float @test_idempotence(float %a) { |
Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 248 | ; CHECK-LABEL: @test_idempotence( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 249 | ; CHECK-NEXT: [[A0:%.*]] = call float @llvm.fabs.f32(float [[A:%.*]]) |
| 250 | ; CHECK-NEXT: [[B0:%.*]] = call float @llvm.floor.f32(float [[A]]) |
| 251 | ; CHECK-NEXT: [[C0:%.*]] = call float @llvm.ceil.f32(float [[A]]) |
| 252 | ; CHECK-NEXT: [[D0:%.*]] = call float @llvm.trunc.f32(float [[A]]) |
| 253 | ; CHECK-NEXT: [[E0:%.*]] = call float @llvm.rint.f32(float [[A]]) |
| 254 | ; CHECK-NEXT: [[F0:%.*]] = call float @llvm.nearbyint.f32(float [[A]]) |
| 255 | ; CHECK-NEXT: [[R0:%.*]] = fadd float [[A0]], [[B0]] |
| 256 | ; CHECK-NEXT: [[R1:%.*]] = fadd float [[R0]], [[C0]] |
| 257 | ; CHECK-NEXT: [[R2:%.*]] = fadd float [[R1]], [[D0]] |
| 258 | ; CHECK-NEXT: [[R3:%.*]] = fadd float [[R2]], [[E0]] |
| 259 | ; CHECK-NEXT: [[R4:%.*]] = fadd float [[R3]], [[F0]] |
| 260 | ; CHECK-NEXT: ret float [[R4]] |
| 261 | ; |
Michael Ilseman | 5485729 | 2013-02-07 19:26:05 +0000 | [diff] [blame] | 262 | |
Michael Ilseman | 5485729 | 2013-02-07 19:26:05 +0000 | [diff] [blame] | 263 | %a0 = call float @llvm.fabs.f32(float %a) |
| 264 | %a1 = call float @llvm.fabs.f32(float %a0) |
| 265 | |
Michael Ilseman | 5485729 | 2013-02-07 19:26:05 +0000 | [diff] [blame] | 266 | %b0 = call float @llvm.floor.f32(float %a) |
| 267 | %b1 = call float @llvm.floor.f32(float %b0) |
| 268 | |
Michael Ilseman | 5485729 | 2013-02-07 19:26:05 +0000 | [diff] [blame] | 269 | %c0 = call float @llvm.ceil.f32(float %a) |
| 270 | %c1 = call float @llvm.ceil.f32(float %c0) |
| 271 | |
Michael Ilseman | 5485729 | 2013-02-07 19:26:05 +0000 | [diff] [blame] | 272 | %d0 = call float @llvm.trunc.f32(float %a) |
| 273 | %d1 = call float @llvm.trunc.f32(float %d0) |
| 274 | |
Michael Ilseman | 5485729 | 2013-02-07 19:26:05 +0000 | [diff] [blame] | 275 | %e0 = call float @llvm.rint.f32(float %a) |
| 276 | %e1 = call float @llvm.rint.f32(float %e0) |
| 277 | |
Michael Ilseman | 5485729 | 2013-02-07 19:26:05 +0000 | [diff] [blame] | 278 | %f0 = call float @llvm.nearbyint.f32(float %a) |
| 279 | %f1 = call float @llvm.nearbyint.f32(float %f0) |
| 280 | |
| 281 | %r0 = fadd float %a1, %b1 |
| 282 | %r1 = fadd float %r0, %c1 |
| 283 | %r2 = fadd float %r1, %d1 |
| 284 | %r3 = fadd float %r2, %e1 |
| 285 | %r4 = fadd float %r3, %f1 |
| 286 | |
| 287 | ret float %r4 |
| 288 | } |
Benjamin Kramer | fd4777c | 2013-09-24 16:37:51 +0000 | [diff] [blame] | 289 | |
| 290 | define i8* @operator_new() { |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 291 | ; CHECK-LABEL: @operator_new( |
| 292 | ; CHECK-NEXT: entry: |
| 293 | ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @_Znwm(i64 8) |
| 294 | ; CHECK-NEXT: br i1 false, label [[CAST_END:%.*]], label [[CAST_NOTNULL:%.*]] |
| 295 | ; CHECK: cast.notnull: |
| 296 | ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 4 |
| 297 | ; CHECK-NEXT: br label [[CAST_END]] |
| 298 | ; CHECK: cast.end: |
| 299 | ; CHECK-NEXT: [[CAST_RESULT:%.*]] = phi i8* [ [[ADD_PTR]], [[CAST_NOTNULL]] ], [ null, [[ENTRY:%.*]] ] |
| 300 | ; CHECK-NEXT: ret i8* [[CAST_RESULT]] |
| 301 | ; |
Benjamin Kramer | fd4777c | 2013-09-24 16:37:51 +0000 | [diff] [blame] | 302 | entry: |
| 303 | %call = tail call noalias i8* @_Znwm(i64 8) |
| 304 | %cmp = icmp eq i8* %call, null |
| 305 | br i1 %cmp, label %cast.end, label %cast.notnull |
| 306 | |
| 307 | cast.notnull: ; preds = %entry |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 308 | %add.ptr = getelementptr inbounds i8, i8* %call, i64 4 |
Benjamin Kramer | fd4777c | 2013-09-24 16:37:51 +0000 | [diff] [blame] | 309 | br label %cast.end |
| 310 | |
| 311 | cast.end: ; preds = %cast.notnull, %entry |
| 312 | %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry ] |
| 313 | ret i8* %cast.result |
| 314 | |
Benjamin Kramer | fd4777c | 2013-09-24 16:37:51 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Philip Reames | 2466719 | 2016-01-04 22:49:23 +0000 | [diff] [blame] | 317 | declare nonnull noalias i8* @_Znwm(i64) |
Benjamin Kramer | 4d4df04 | 2013-09-24 17:15:14 +0000 | [diff] [blame] | 318 | |
Benjamin Kramer | d59bf25 | 2013-09-24 18:37:49 +0000 | [diff] [blame] | 319 | %"struct.std::nothrow_t" = type { i8 } |
| 320 | @_ZSt7nothrow = external global %"struct.std::nothrow_t" |
| 321 | |
| 322 | define i8* @operator_new_nothrow_t() { |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 323 | ; CHECK-LABEL: @operator_new_nothrow_t( |
| 324 | ; CHECK-NEXT: entry: |
| 325 | ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @_ZnamRKSt9nothrow_t(i64 8, %"struct.std::nothrow_t"* @_ZSt7nothrow) |
| 326 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[CALL]], null |
| 327 | ; CHECK-NEXT: br i1 [[CMP]], label [[CAST_END:%.*]], label [[CAST_NOTNULL:%.*]] |
| 328 | ; CHECK: cast.notnull: |
| 329 | ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 4 |
| 330 | ; CHECK-NEXT: br label [[CAST_END]] |
| 331 | ; CHECK: cast.end: |
| 332 | ; CHECK-NEXT: [[CAST_RESULT:%.*]] = phi i8* [ [[ADD_PTR]], [[CAST_NOTNULL]] ], [ null, [[ENTRY:%.*]] ] |
| 333 | ; CHECK-NEXT: ret i8* [[CAST_RESULT]] |
| 334 | ; |
Benjamin Kramer | d59bf25 | 2013-09-24 18:37:49 +0000 | [diff] [blame] | 335 | entry: |
| 336 | %call = tail call noalias i8* @_ZnamRKSt9nothrow_t(i64 8, %"struct.std::nothrow_t"* @_ZSt7nothrow) |
| 337 | %cmp = icmp eq i8* %call, null |
| 338 | br i1 %cmp, label %cast.end, label %cast.notnull |
| 339 | |
| 340 | cast.notnull: ; preds = %entry |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 341 | %add.ptr = getelementptr inbounds i8, i8* %call, i64 4 |
Benjamin Kramer | d59bf25 | 2013-09-24 18:37:49 +0000 | [diff] [blame] | 342 | br label %cast.end |
| 343 | |
| 344 | cast.end: ; preds = %cast.notnull, %entry |
| 345 | %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry ] |
| 346 | ret i8* %cast.result |
| 347 | |
Benjamin Kramer | d59bf25 | 2013-09-24 18:37:49 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | declare i8* @_ZnamRKSt9nothrow_t(i64, %"struct.std::nothrow_t"*) nounwind |
| 351 | |
Benjamin Kramer | 4d4df04 | 2013-09-24 17:15:14 +0000 | [diff] [blame] | 352 | define i8* @malloc_can_return_null() { |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 353 | ; CHECK-LABEL: @malloc_can_return_null( |
| 354 | ; CHECK-NEXT: entry: |
| 355 | ; CHECK-NEXT: [[CALL:%.*]] = tail call noalias i8* @malloc(i64 8) |
| 356 | ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8* [[CALL]], null |
| 357 | ; CHECK-NEXT: br i1 [[CMP]], label [[CAST_END:%.*]], label [[CAST_NOTNULL:%.*]] |
| 358 | ; CHECK: cast.notnull: |
| 359 | ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, i8* [[CALL]], i64 4 |
| 360 | ; CHECK-NEXT: br label [[CAST_END]] |
| 361 | ; CHECK: cast.end: |
| 362 | ; CHECK-NEXT: [[CAST_RESULT:%.*]] = phi i8* [ [[ADD_PTR]], [[CAST_NOTNULL]] ], [ null, [[ENTRY:%.*]] ] |
| 363 | ; CHECK-NEXT: ret i8* [[CAST_RESULT]] |
| 364 | ; |
Benjamin Kramer | 4d4df04 | 2013-09-24 17:15:14 +0000 | [diff] [blame] | 365 | entry: |
| 366 | %call = tail call noalias i8* @malloc(i64 8) |
| 367 | %cmp = icmp eq i8* %call, null |
| 368 | br i1 %cmp, label %cast.end, label %cast.notnull |
| 369 | |
| 370 | cast.notnull: ; preds = %entry |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 371 | %add.ptr = getelementptr inbounds i8, i8* %call, i64 4 |
Benjamin Kramer | 4d4df04 | 2013-09-24 17:15:14 +0000 | [diff] [blame] | 372 | br label %cast.end |
| 373 | |
| 374 | cast.end: ; preds = %cast.notnull, %entry |
| 375 | %cast.result = phi i8* [ %add.ptr, %cast.notnull ], [ null, %entry ] |
| 376 | ret i8* %cast.result |
| 377 | |
Benjamin Kramer | 4d4df04 | 2013-09-24 17:15:14 +0000 | [diff] [blame] | 378 | } |
| 379 | |
David Majnemer | bb53d23 | 2016-06-25 07:37:30 +0000 | [diff] [blame] | 380 | define i32 @call_null() { |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 381 | ; CHECK-LABEL: @call_null( |
| 382 | ; CHECK-NEXT: entry: |
| 383 | ; CHECK-NEXT: [[CALL:%.*]] = call i32 null() |
| 384 | ; CHECK-NEXT: ret i32 undef |
| 385 | ; |
David Majnemer | bb53d23 | 2016-06-25 07:37:30 +0000 | [diff] [blame] | 386 | entry: |
| 387 | %call = call i32 null() |
| 388 | ret i32 %call |
| 389 | } |
David Majnemer | bb53d23 | 2016-06-25 07:37:30 +0000 | [diff] [blame] | 390 | |
| 391 | define i32 @call_undef() { |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 392 | ; CHECK-LABEL: @call_undef( |
| 393 | ; CHECK-NEXT: entry: |
| 394 | ; CHECK-NEXT: [[CALL:%.*]] = call i32 undef() |
| 395 | ; CHECK-NEXT: ret i32 undef |
| 396 | ; |
David Majnemer | bb53d23 | 2016-06-25 07:37:30 +0000 | [diff] [blame] | 397 | entry: |
| 398 | %call = call i32 undef() |
| 399 | ret i32 %call |
| 400 | } |
David Majnemer | bb53d23 | 2016-06-25 07:37:30 +0000 | [diff] [blame] | 401 | |
David Majnemer | 7f781ab | 2016-07-14 00:29:50 +0000 | [diff] [blame] | 402 | @GV = private constant [8 x i32] [i32 42, i32 43, i32 44, i32 45, i32 46, i32 47, i32 48, i32 49] |
| 403 | |
| 404 | define <8 x i32> @partial_masked_load() { |
| 405 | ; CHECK-LABEL: @partial_masked_load( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 406 | ; CHECK-NEXT: ret <8 x i32> <i32 undef, i32 undef, i32 42, i32 43, i32 44, i32 45, i32 46, i32 47> |
| 407 | ; |
David Majnemer | 7f781ab | 2016-07-14 00:29:50 +0000 | [diff] [blame] | 408 | %masked.load = call <8 x i32> @llvm.masked.load.v8i32.p0v8i32(<8 x i32>* bitcast (i32* getelementptr ([8 x i32], [8 x i32]* @GV, i64 0, i64 -2) to <8 x i32>*), i32 4, <8 x i1> <i1 false, i1 false, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i32> undef) |
| 409 | ret <8 x i32> %masked.load |
| 410 | } |
| 411 | |
David Majnemer | 17a95aa | 2016-07-14 06:58:37 +0000 | [diff] [blame] | 412 | define <8 x i32> @masked_load_undef_mask(<8 x i32>* %V) { |
| 413 | ; CHECK-LABEL: @masked_load_undef_mask( |
Craig Topper | 15288da | 2017-05-23 17:57:36 +0000 | [diff] [blame] | 414 | ; CHECK-NEXT: ret <8 x i32> <i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 0> |
| 415 | ; |
David Majnemer | 17a95aa | 2016-07-14 06:58:37 +0000 | [diff] [blame] | 416 | %masked.load = call <8 x i32> @llvm.masked.load.v8i32.p0v8i32(<8 x i32>* %V, i32 4, <8 x i1> undef, <8 x i32> <i32 1, i32 0, i32 1, i32 0, i32 1, i32 0, i32 1, i32 0>) |
| 417 | ret <8 x i32> %masked.load |
| 418 | } |
| 419 | |
Benjamin Kramer | 4d4df04 | 2013-09-24 17:15:14 +0000 | [diff] [blame] | 420 | declare noalias i8* @malloc(i64) |
David Majnemer | 7f781ab | 2016-07-14 00:29:50 +0000 | [diff] [blame] | 421 | |
| 422 | declare <8 x i32> @llvm.masked.load.v8i32.p0v8i32(<8 x i32>*, i32, <8 x i1>, <8 x i32>) |
Craig Topper | 97f113e | 2017-06-04 07:30:23 +0000 | [diff] [blame^] | 423 | |
| 424 | declare double @llvm.powi.f64(double, i32) |
| 425 | declare <2 x double> @llvm.powi.v2f64(<2 x double>, i32) |
| 426 | |
| 427 | define double @constant_fold_powi() nounwind uwtable ssp { |
| 428 | ; CHECK-LABEL: @constant_fold_powi( |
| 429 | ; CHECK-NEXT: entry: |
| 430 | ; CHECK-NEXT: ret double 9.000000e+00 |
| 431 | ; |
| 432 | entry: |
| 433 | %0 = call double @llvm.powi.f64(double 3.00000e+00, i32 2) |
| 434 | ret double %0 |
| 435 | } |
| 436 | |
| 437 | define <2 x double> @constant_fold_powi_vec() nounwind uwtable ssp { |
| 438 | ; CHECK-LABEL: @constant_fold_powi_vec( |
| 439 | ; CHECK-NEXT: entry: |
| 440 | ; CHECK-NEXT: [[TMP0:%.*]] = call <2 x double> @llvm.powi.v2f64(<2 x double> <double 3.000000e+00, double 5.000000e+00>, i32 2) |
| 441 | ; CHECK-NEXT: ret <2 x double> [[TMP0]] |
| 442 | ; |
| 443 | entry: |
| 444 | %0 = call <2 x double> @llvm.powi.v2f64(<2 x double> <double 3.00000e+00, double 5.00000e+00>, i32 2) |
| 445 | ret <2 x double> %0 |
| 446 | } |