1 ; RUN: opt -S < %s -jump-threading | FileCheck %s
3 ; Keep block addresses alive.
4 @addresses = constant [4 x i8*] [
5 i8* blockaddress(@test1, %L1), i8* blockaddress(@test1, %L2),
6 i8* blockaddress(@test2, %L1), i8* blockaddress(@test2, %L2)
14 ; Check basic jump threading for indirectbr instructions.
17 ; CHECK: br i1 %tobool, label %L1, label %indirectgoto
20 ; CHECK: indirectbr i8* %address, [label %L1, label %L2]
21 define void @test1(i32 %i, i8* %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 i8* [ %address, %if.else ], [ blockaddress(@test1, %L1), %entry ]
40 indirectbr i8* %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 i8* 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(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 ptrtoint (i8* blockaddress(@test3, %__here) to i64)) nounwind noredzone
85 __here1: ; preds = %__here
86 %call2 = call i32 (...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 ptrtoint (i8* blockaddress(@test3, %__here1) to i64)) nounwind noredzone
89 __here3: ; preds = %__here1
90 %call4 = call i32 (...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64 ptrtoint (i8* blockaddress(@test3, %__here3) to i64)) nounwind noredzone
94 declare i32 @printf(...) noredzone