1 ; RUN: opt -S < %s -passes=jump-threading | FileCheck %s
3 ; Keep block addresses alive.
4 @addresses = constant [4 x ptr] [
5 ptr blockaddress(@test1, %L1), ptr blockaddress(@test1, %L2),
6 ptr blockaddress(@test2, %L1), ptr blockaddress(@test2, %L2)
14 ; Check basic jump threading for indirectbr instructions.
17 ; CHECK: br i1 %tobool, label %L1, label %indirectgoto
20 ; CHECK: indirectbr ptr %address, [label %L1, label %L2]
21 define void @test1(i32 %i, ptr %address) nounwind {
24 %tobool = icmp ne i32 %rem, 0
25 br i1 %tobool, label %indirectgoto, label %if.else
27 if.else: ; preds = %entry
28 br label %indirectgoto
30 L1: ; preds = %indirectgoto
34 L2: ; preds = %indirectgoto
38 indirectgoto: ; preds = %if.else, %entry
39 %indirect.goto.dest = phi ptr [ %address, %if.else ], [ blockaddress(@test1, %L1), %entry ]
40 indirectbr ptr %indirect.goto.dest, [label %L1, label %L2]
44 ; Check constant folding of indirectbr
48 ; CHECK-NEXT: br label %L1
50 ; CHECK-NEXT: call void @bar
51 ; CHECK-NEXT: ret void
52 define void @test2() nounwind {
54 indirectbr ptr blockaddress(@test2, %L1), [label %L1, label %L2]
56 L1: ; preds = %indirectgoto
60 L2: ; preds = %indirectgoto
67 ; Don't merge address-taken blocks.
68 @.str = private unnamed_addr constant [4 x i8] c"%p\0A\00"
70 ; CHECK-LABEL: @test3(
72 ; CHECK: blockaddress(@test3, %__here)
74 ; CHECK: blockaddress(@test3, %__here1)
76 ; CHECK: blockaddress(@test3, %__here3)
77 define void @test3() nounwind ssp noredzone {
81 __here: ; preds = %entry
82 %call = call i32 (...) @printf(ptr @.str, i64 ptrtoint (ptr blockaddress(@test3, %__here) to i64)) nounwind noredzone
85 __here1: ; preds = %__here
86 %call2 = call i32 (...) @printf(ptr @.str, i64 ptrtoint (ptr blockaddress(@test3, %__here1) to i64)) nounwind noredzone
89 __here3: ; preds = %__here1
90 %call4 = call i32 (...) @printf(ptr @.str, i64 ptrtoint (ptr blockaddress(@test3, %__here3) to i64)) nounwind noredzone
94 declare i32 @printf(...) noredzone