1 ; RUN: opt < %s -indirectbr-expand -S | FileCheck %s
2 ; RUN: opt < %s -passes=indirectbr-expand -S | FileCheck %s
4 ; REQUIRES: x86-registered-target
6 target triple = "x86_64-unknown-linux-gnu"
8 @test1.targets = constant [4 x ptr] [ptr blockaddress(@test1, %bb0),
9 ptr blockaddress(@test1, %bb1),
10 ptr blockaddress(@test1, %bb2),
11 ptr blockaddress(@test1, %bb3)]
12 ; CHECK-LABEL: @test1.targets = constant [4 x ptr]
13 ; CHECK: [ptr inttoptr (i64 1 to ptr),
14 ; CHECK: ptr inttoptr (i64 2 to ptr),
15 ; CHECK: ptr inttoptr (i64 3 to ptr),
16 ; CHECK: ptr blockaddress(@test1, %bb3)]
18 define void @test1(ptr readonly %p, ptr %sink) #0 {
19 ; CHECK-LABEL: define void @test1(
21 %i0 = load i64, ptr %p
22 %target.i0 = getelementptr [4 x ptr], ptr @test1.targets, i64 0, i64 %i0
23 %target0 = load ptr, ptr %target.i0
24 ; Only a subset of blocks are viable successors here.
25 indirectbr ptr %target0, [label %bb0, label %bb1]
26 ; CHECK-NOT: indirectbr
27 ; CHECK: %[[ENTRY_V:.*]] = ptrtoint ptr %{{.*}} to i64
28 ; CHECK-NEXT: br label %[[SWITCH_BB:.*]]
31 store volatile i64 0, ptr %sink
35 store volatile i64 1, ptr %sink
39 store volatile i64 2, ptr %sink
43 store volatile i64 3, ptr %sink
47 %i.next = load i64, ptr %p
48 %target.i.next = getelementptr [4 x ptr], ptr @test1.targets, i64 0, i64 %i.next
49 %target.next = load ptr, ptr %target.i.next
50 ; A different subset of blocks are viable successors here.
51 indirectbr ptr %target.next, [label %bb1, label %bb2]
52 ; CHECK-NOT: indirectbr
53 ; CHECK: %[[LATCH_V:.*]] = ptrtoint ptr %{{.*}} to i64
54 ; CHECK-NEXT: br label %[[SWITCH_BB]]
56 ; CHECK: [[SWITCH_BB]]:
57 ; CHECK-NEXT: %[[V:.*]] = phi i64 [ %[[ENTRY_V]], %entry ], [ %[[LATCH_V]], %latch ]
58 ; CHECK-NEXT: switch i64 %[[V]], label %bb0 [
59 ; CHECK-NEXT: i64 2, label %bb1
60 ; CHECK-NEXT: i64 3, label %bb2
64 attributes #0 = { "target-features"="+retpoline" }