1; RUN: opt -S -bdce -instsimplify < %s | FileCheck %s 2; RUN: opt -S -instsimplify < %s | FileCheck %s -check-prefix=CHECK-IO 3target datalayout = "E-m:e-i64:64-n32:64" 4target triple = "powerpc64-unknown-linux-gnu" 5 6; Function Attrs: nounwind readnone 7define signext i32 @bar(i32 signext %x) #0 { 8entry: 9 %call = tail call signext i32 @foo(i32 signext 5) #0 10 %and = and i32 %call, 4 11 %or = or i32 %and, %x 12 %call1 = tail call signext i32 @foo(i32 signext 3) #0 13 %and2 = and i32 %call1, 8 14 %or3 = or i32 %or, %and2 15 %call4 = tail call signext i32 @foo(i32 signext 2) #0 16 %and5 = and i32 %call4, 16 17 %or6 = or i32 %or3, %and5 18 %call7 = tail call signext i32 @foo(i32 signext 1) #0 19 %and8 = and i32 %call7, 32 20 %or9 = or i32 %or6, %and8 21 %call10 = tail call signext i32 @foo(i32 signext 0) #0 22 %and11 = and i32 %call10, 64 23 %or12 = or i32 %or9, %and11 24 %call13 = tail call signext i32 @foo(i32 signext 4) #0 25 %and14 = and i32 %call13, 128 26 %or15 = or i32 %or12, %and14 27 %shr = ashr i32 %or15, 4 28 ret i32 %shr 29 30; CHECK-LABEL: @bar 31; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 32; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 33; CHECK: tail call signext i32 @foo(i32 signext 2) 34; CHECK: tail call signext i32 @foo(i32 signext 1) 35; CHECK: tail call signext i32 @foo(i32 signext 0) 36; CHECK: tail call signext i32 @foo(i32 signext 4) 37; CHECK: ret i32 38 39; Check that instsimplify is not doing this all on its own. 40; CHECK-IO-LABEL: @bar 41; CHECK-IO: tail call signext i32 @foo(i32 signext 5) 42; CHECK-IO: tail call signext i32 @foo(i32 signext 3) 43; CHECK-IO: tail call signext i32 @foo(i32 signext 2) 44; CHECK-IO: tail call signext i32 @foo(i32 signext 1) 45; CHECK-IO: tail call signext i32 @foo(i32 signext 0) 46; CHECK-IO: tail call signext i32 @foo(i32 signext 4) 47; CHECK-IO: ret i32 48} 49 50; Function Attrs: nounwind readnone 51declare signext i32 @foo(i32 signext) #0 52 53; Function Attrs: nounwind readnone 54define signext i32 @far(i32 signext %x) #1 { 55entry: 56 %call = tail call signext i32 @goo(i32 signext 5) #1 57 %and = and i32 %call, 4 58 %or = or i32 %and, %x 59 %call1 = tail call signext i32 @goo(i32 signext 3) #1 60 %and2 = and i32 %call1, 8 61 %or3 = or i32 %or, %and2 62 %call4 = tail call signext i32 @goo(i32 signext 2) #1 63 %and5 = and i32 %call4, 16 64 %or6 = or i32 %or3, %and5 65 %call7 = tail call signext i32 @goo(i32 signext 1) #1 66 %and8 = and i32 %call7, 32 67 %or9 = or i32 %or6, %and8 68 %call10 = tail call signext i32 @goo(i32 signext 0) #1 69 %and11 = and i32 %call10, 64 70 %or12 = or i32 %or9, %and11 71 %call13 = tail call signext i32 @goo(i32 signext 4) #1 72 %and14 = and i32 %call13, 128 73 %or15 = or i32 %or12, %and14 74 %shr = ashr i32 %or15, 4 75 ret i32 %shr 76 77; CHECK-LABEL: @far 78; Calls to foo(5) and foo(3) are still there, but their results are not used. 79; CHECK: tail call signext i32 @goo(i32 signext 5) 80; CHECK-NEXT: tail call signext i32 @goo(i32 signext 3) 81; CHECK-NEXT: tail call signext i32 @goo(i32 signext 2) 82; CHECK: tail call signext i32 @goo(i32 signext 1) 83; CHECK: tail call signext i32 @goo(i32 signext 0) 84; CHECK: tail call signext i32 @goo(i32 signext 4) 85; CHECK: ret i32 86 87; Check that instsimplify is not doing this all on its own. 88; CHECK-IO-LABEL: @far 89; CHECK-IO: tail call signext i32 @goo(i32 signext 5) 90; CHECK-IO: tail call signext i32 @goo(i32 signext 3) 91; CHECK-IO: tail call signext i32 @goo(i32 signext 2) 92; CHECK-IO: tail call signext i32 @goo(i32 signext 1) 93; CHECK-IO: tail call signext i32 @goo(i32 signext 0) 94; CHECK-IO: tail call signext i32 @goo(i32 signext 4) 95; CHECK-IO: ret i32 96} 97 98declare signext i32 @goo(i32 signext) #1 99 100; Function Attrs: nounwind readnone 101define signext i32 @tar1(i32 signext %x) #0 { 102entry: 103 %call = tail call signext i32 @foo(i32 signext 5) #0 104 %and = and i32 %call, 33554432 105 %or = or i32 %and, %x 106 %call1 = tail call signext i32 @foo(i32 signext 3) #0 107 %and2 = and i32 %call1, 67108864 108 %or3 = or i32 %or, %and2 109 %call4 = tail call signext i32 @foo(i32 signext 2) #0 110 %and5 = and i32 %call4, 16 111 %or6 = or i32 %or3, %and5 112 %call7 = tail call signext i32 @foo(i32 signext 1) #0 113 %and8 = and i32 %call7, 32 114 %or9 = or i32 %or6, %and8 115 %call10 = tail call signext i32 @foo(i32 signext 0) #0 116 %and11 = and i32 %call10, 64 117 %or12 = or i32 %or9, %and11 118 %call13 = tail call signext i32 @foo(i32 signext 4) #0 119 %and14 = and i32 %call13, 128 120 %or15 = or i32 %or12, %and14 121 %bs = tail call i32 @llvm.bswap.i32(i32 %or15) #0 122 %shr = ashr i32 %bs, 4 123 ret i32 %shr 124 125; CHECK-LABEL: @tar1 126; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 127; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 128; CHECK: tail call signext i32 @foo(i32 signext 2) 129; CHECK: tail call signext i32 @foo(i32 signext 1) 130; CHECK: tail call signext i32 @foo(i32 signext 0) 131; CHECK: tail call signext i32 @foo(i32 signext 4) 132; CHECK: ret i32 133} 134 135; Function Attrs: nounwind readnone 136declare i32 @llvm.bswap.i32(i32) #0 137 138; Function Attrs: nounwind readnone 139define signext i32 @tar2(i32 signext %x) #0 { 140entry: 141 %call = tail call signext i32 @foo(i32 signext 5) #0 142 %and = and i32 %call, 33554432 143 %or = or i32 %and, %x 144 %call1 = tail call signext i32 @foo(i32 signext 3) #0 145 %and2 = and i32 %call1, 67108864 146 %or3 = or i32 %or, %and2 147 %call4 = tail call signext i32 @foo(i32 signext 2) #0 148 %and5 = and i32 %call4, 16 149 %or6 = or i32 %or3, %and5 150 %call7 = tail call signext i32 @foo(i32 signext 1) #0 151 %and8 = and i32 %call7, 32 152 %or9 = or i32 %or6, %and8 153 %call10 = tail call signext i32 @foo(i32 signext 0) #0 154 %and11 = and i32 %call10, 64 155 %or12 = or i32 %or9, %and11 156 %call13 = tail call signext i32 @foo(i32 signext 4) #0 157 %and14 = and i32 %call13, 128 158 %or15 = or i32 %or12, %and14 159 %shl = shl i32 %or15, 10 160 ret i32 %shl 161 162; CHECK-LABEL: @tar2 163; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 164; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 165; CHECK: tail call signext i32 @foo(i32 signext 2) 166; CHECK: tail call signext i32 @foo(i32 signext 1) 167; CHECK: tail call signext i32 @foo(i32 signext 0) 168; CHECK: tail call signext i32 @foo(i32 signext 4) 169; CHECK: ret i32 170} 171 172; Function Attrs: nounwind readnone 173define signext i32 @tar3(i32 signext %x) #0 { 174entry: 175 %call = tail call signext i32 @foo(i32 signext 5) #0 176 %and = and i32 %call, 33554432 177 %or = or i32 %and, %x 178 %call1 = tail call signext i32 @foo(i32 signext 3) #0 179 %and2 = and i32 %call1, 67108864 180 %or3 = or i32 %or, %and2 181 %call4 = tail call signext i32 @foo(i32 signext 2) #0 182 %and5 = and i32 %call4, 16 183 %or6 = or i32 %or3, %and5 184 %call7 = tail call signext i32 @foo(i32 signext 1) #0 185 %and8 = and i32 %call7, 32 186 %or9 = or i32 %or6, %and8 187 %call10 = tail call signext i32 @foo(i32 signext 0) #0 188 %and11 = and i32 %call10, 64 189 %or12 = or i32 %or9, %and11 190 %call13 = tail call signext i32 @foo(i32 signext 4) #0 191 %and14 = and i32 %call13, 128 192 %or15 = or i32 %or12, %and14 193 %add = add i32 %or15, 5 194 %shl = shl i32 %add, 10 195 ret i32 %shl 196 197; CHECK-LABEL: @tar3 198; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 199; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 200; CHECK: tail call signext i32 @foo(i32 signext 2) 201; CHECK: tail call signext i32 @foo(i32 signext 1) 202; CHECK: tail call signext i32 @foo(i32 signext 0) 203; CHECK: tail call signext i32 @foo(i32 signext 4) 204; CHECK: ret i32 205} 206 207; Function Attrs: nounwind readnone 208define signext i32 @tar4(i32 signext %x) #0 { 209entry: 210 %call = tail call signext i32 @foo(i32 signext 5) #0 211 %and = and i32 %call, 33554432 212 %or = or i32 %and, %x 213 %call1 = tail call signext i32 @foo(i32 signext 3) #0 214 %and2 = and i32 %call1, 67108864 215 %or3 = or i32 %or, %and2 216 %call4 = tail call signext i32 @foo(i32 signext 2) #0 217 %and5 = and i32 %call4, 16 218 %or6 = or i32 %or3, %and5 219 %call7 = tail call signext i32 @foo(i32 signext 1) #0 220 %and8 = and i32 %call7, 32 221 %or9 = or i32 %or6, %and8 222 %call10 = tail call signext i32 @foo(i32 signext 0) #0 223 %and11 = and i32 %call10, 64 224 %or12 = or i32 %or9, %and11 225 %call13 = tail call signext i32 @foo(i32 signext 4) #0 226 %and14 = and i32 %call13, 128 227 %or15 = or i32 %or12, %and14 228 %sub = sub i32 %or15, 5 229 %shl = shl i32 %sub, 10 230 ret i32 %shl 231 232; CHECK-LABEL: @tar4 233; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 234; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 235; CHECK: tail call signext i32 @foo(i32 signext 2) 236; CHECK: tail call signext i32 @foo(i32 signext 1) 237; CHECK: tail call signext i32 @foo(i32 signext 0) 238; CHECK: tail call signext i32 @foo(i32 signext 4) 239; CHECK: ret i32 240} 241 242; Function Attrs: nounwind readnone 243define signext i32 @tar5(i32 signext %x) #0 { 244entry: 245 %call = tail call signext i32 @foo(i32 signext 5) #0 246 %and = and i32 %call, 33554432 247 %or = or i32 %and, %x 248 %call1 = tail call signext i32 @foo(i32 signext 3) #0 249 %and2 = and i32 %call1, 67108864 250 %or3 = or i32 %or, %and2 251 %call4 = tail call signext i32 @foo(i32 signext 2) #0 252 %and5 = and i32 %call4, 16 253 %or6 = or i32 %or3, %and5 254 %call7 = tail call signext i32 @foo(i32 signext 1) #0 255 %and8 = and i32 %call7, 32 256 %or9 = or i32 %or6, %and8 257 %call10 = tail call signext i32 @foo(i32 signext 0) #0 258 %and11 = and i32 %call10, 64 259 %or12 = or i32 %or9, %and11 260 %call13 = tail call signext i32 @foo(i32 signext 4) #0 261 %and14 = and i32 %call13, 128 262 %or15 = or i32 %or12, %and14 263 %xor = xor i32 %or15, 5 264 %shl = shl i32 %xor, 10 265 ret i32 %shl 266 267; CHECK-LABEL: @tar5 268; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 269; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 270; CHECK: tail call signext i32 @foo(i32 signext 2) 271; CHECK: tail call signext i32 @foo(i32 signext 1) 272; CHECK: tail call signext i32 @foo(i32 signext 0) 273; CHECK: tail call signext i32 @foo(i32 signext 4) 274; CHECK: ret i32 275} 276 277; Function Attrs: nounwind readnone 278define signext i32 @tar7(i32 signext %x, i1 %b) #0 { 279entry: 280 %call = tail call signext i32 @foo(i32 signext 5) #0 281 %and = and i32 %call, 33554432 282 %or = or i32 %and, %x 283 %call1 = tail call signext i32 @foo(i32 signext 3) #0 284 %and2 = and i32 %call1, 67108864 285 %or3 = or i32 %or, %and2 286 %call4 = tail call signext i32 @foo(i32 signext 2) #0 287 %and5 = and i32 %call4, 16 288 %or6 = or i32 %or3, %and5 289 %call7 = tail call signext i32 @foo(i32 signext 1) #0 290 %and8 = and i32 %call7, 32 291 %or9 = or i32 %or6, %and8 292 %call10 = tail call signext i32 @foo(i32 signext 0) #0 293 %and11 = and i32 %call10, 64 294 %or12 = or i32 %or9, %and11 295 %call13 = tail call signext i32 @foo(i32 signext 4) #0 296 %and14 = and i32 %call13, 128 297 %or15 = or i32 %or12, %and14 298 %v = select i1 %b, i32 %or15, i32 5 299 %shl = shl i32 %v, 10 300 ret i32 %shl 301 302; CHECK-LABEL: @tar7 303; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 304; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 305; CHECK: tail call signext i32 @foo(i32 signext 2) 306; CHECK: tail call signext i32 @foo(i32 signext 1) 307; CHECK: tail call signext i32 @foo(i32 signext 0) 308; CHECK: tail call signext i32 @foo(i32 signext 4) 309; CHECK: ret i32 310} 311 312; Function Attrs: nounwind readnone 313define signext i16 @tar8(i32 signext %x) #0 { 314entry: 315 %call = tail call signext i32 @foo(i32 signext 5) #0 316 %and = and i32 %call, 33554432 317 %or = or i32 %and, %x 318 %call1 = tail call signext i32 @foo(i32 signext 3) #0 319 %and2 = and i32 %call1, 67108864 320 %or3 = or i32 %or, %and2 321 %call4 = tail call signext i32 @foo(i32 signext 2) #0 322 %and5 = and i32 %call4, 16 323 %or6 = or i32 %or3, %and5 324 %call7 = tail call signext i32 @foo(i32 signext 1) #0 325 %and8 = and i32 %call7, 32 326 %or9 = or i32 %or6, %and8 327 %call10 = tail call signext i32 @foo(i32 signext 0) #0 328 %and11 = and i32 %call10, 64 329 %or12 = or i32 %or9, %and11 330 %call13 = tail call signext i32 @foo(i32 signext 4) #0 331 %and14 = and i32 %call13, 128 332 %or15 = or i32 %or12, %and14 333 %tr = trunc i32 %or15 to i16 334 ret i16 %tr 335 336; CHECK-LABEL: @tar8 337; CHECK-NOT: tail call signext i32 @foo(i32 signext 5) 338; CHECK-NOT: tail call signext i32 @foo(i32 signext 3) 339; CHECK: tail call signext i32 @foo(i32 signext 2) 340; CHECK: tail call signext i32 @foo(i32 signext 1) 341; CHECK: tail call signext i32 @foo(i32 signext 0) 342; CHECK: tail call signext i32 @foo(i32 signext 4) 343; CHECK: ret i16 344} 345 346attributes #0 = { nounwind readnone } 347attributes #1 = { nounwind } 348 349