aboutsummaryrefslogtreecommitdiffstats
path: root/test/Transforms/JumpThreading/indirectbr.ll
blob: 6c5321d3194a63d1dbf87b523e7a260a4cc61853 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
; RUN: opt -S < %s -jump-threading | FileCheck %s

; Keep block addresses alive.
@addresses = constant [4 x i8*] [
  i8* blockaddress(@test1, %L1), i8* blockaddress(@test1, %L2),
  i8* blockaddress(@test2, %L1), i8* blockaddress(@test2, %L2)
]

declare void @bar()
declare void @baz()



; Check basic jump threading for indirectbr instructions.

; CHECK: void @test1
; CHECK: br i1 %tobool, label %L1, label %indirectgoto
; CHECK-NOT: if.else:
; CHECK: L1:
; CHECK: indirectbr i8* %address, [label %L1, label %L2]
define void @test1(i32 %i, i8* %address) nounwind {
entry:
  %rem = srem i32 %i, 2
  %tobool = icmp ne i32 %rem, 0
  br i1 %tobool, label %indirectgoto, label %if.else

if.else:                                          ; preds = %entry
  br label %indirectgoto

L1:                                               ; preds = %indirectgoto
  call void @bar()
  ret void

L2:                                               ; preds = %indirectgoto
  call void @baz()
  ret void

indirectgoto:                                     ; preds = %if.else, %entry
  %indirect.goto.dest = phi i8* [ %address, %if.else ], [ blockaddress(@test1, %L1), %entry ]
  indirectbr i8* %indirect.goto.dest, [label %L1, label %L2]
}


; Check constant folding of indirectbr

; CHECK: void @test2
; CHECK-NEXT: :
; CHECK-NEXT: call void @bar
; CHECK-NEXT: ret void
define void @test2() nounwind {
entry:
  indirectbr i8* blockaddress(@test2, %L1), [label %L1, label %L2]

L1:                                               ; preds = %indirectgoto
  call void @bar()
  ret void

L2:                                               ; preds = %indirectgoto
  call void @baz()
  ret void
}