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