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 i8*] [i8* blockaddress(@test1, %bb0),
8 i8* blockaddress(@test1, %bb1),
9 i8* blockaddress(@test1, %bb2),
10 i8* blockaddress(@test1, %bb3)]
11 ; CHECK-LABEL: @test1.targets = constant [4 x i8*]
12 ; CHECK: [i8* inttoptr (i64 1 to i8*),
13 ; CHECK: i8* inttoptr (i64 2 to i8*),
14 ; CHECK: i8* inttoptr (i64 3 to i8*),
15 ; CHECK: i8* blockaddress(@test1, %bb3)]
17 define void @test1(i64* readonly %p, i64* %sink) #0 {
18 ; CHECK-LABEL: define void @test1(
20 %i0 = load i64, i64* %p
21 %target.i0 = getelementptr [4 x i8*], [4 x i8*]* @test1.targets, i64 0, i64 %i0
22 %target0 = load i8*, i8** %target.i0
23 ; Only a subset of blocks are viable successors here.
24 indirectbr i8* %target0, [label %bb0, label %bb1]
25 ; CHECK-NOT: indirectbr
26 ; CHECK: %[[ENTRY_V:.*]] = ptrtoint i8* %{{.*}} to i64
27 ; CHECK-NEXT: br label %[[SWITCH_BB:.*]]
30 store volatile i64 0, i64* %sink
34 store volatile i64 1, i64* %sink
38 store volatile i64 2, i64* %sink
42 store volatile i64 3, i64* %sink
46 %i.next = load i64, i64* %p
47 %target.i.next = getelementptr [4 x i8*], [4 x i8*]* @test1.targets, i64 0, i64 %i.next
48 %target.next = load i8*, i8** %target.i.next
49 ; A different subset of blocks are viable successors here.
50 indirectbr i8* %target.next, [label %bb1, label %bb2]
51 ; CHECK-NOT: indirectbr
52 ; CHECK: %[[LATCH_V:.*]] = ptrtoint i8* %{{.*}} 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" }