blob: d654056eaf3dc53285411cca60a3a5b2c95138db [file] [log] [blame]
Chad Rosier1a1531d2012-01-26 18:24:25 +00001; RUN: llc < %s -mtriple=thumb-apple-darwin -relocation-model=dynamic-no-pic -mcpu=cortex-a8 -asm-verbose=false | FileCheck %s
2
3; We should be able to tail-duplicate the basic block containing the indirectbr
4; into all of its predecessors.
Stephen Lind24ab202013-07-14 06:24:09 +00005; CHECK-LABEL: fn:
Chad Rosier1a1531d2012-01-26 18:24:25 +00006; CHECK: mov pc
7; CHECK: mov pc
8; CHECK: mov pc
9
10@fn.codetable = internal unnamed_addr constant [3 x i8*] [i8* blockaddress(@fn, %RETURN), i8* blockaddress(@fn, %INCREMENT), i8* blockaddress(@fn, %DECREMENT)], align 4
11
12define i32 @fn(i32* nocapture %opcodes) nounwind readonly ssp {
13entry:
Manman Ren1a5ff282013-04-30 17:52:57 +000014 %0 = load i32* %opcodes, align 4
Chad Rosier1a1531d2012-01-26 18:24:25 +000015 %arrayidx = getelementptr inbounds [3 x i8*]* @fn.codetable, i32 0, i32 %0
16 br label %indirectgoto
17
18INCREMENT: ; preds = %indirectgoto
19 %inc = add nsw i32 %result.0, 1
Manman Ren1a5ff282013-04-30 17:52:57 +000020 %1 = load i32* %opcodes.addr.0, align 4
Chad Rosier1a1531d2012-01-26 18:24:25 +000021 %arrayidx2 = getelementptr inbounds [3 x i8*]* @fn.codetable, i32 0, i32 %1
22 br label %indirectgoto
23
24DECREMENT: ; preds = %indirectgoto
25 %dec = add nsw i32 %result.0, -1
Manman Ren1a5ff282013-04-30 17:52:57 +000026 %2 = load i32* %opcodes.addr.0, align 4
Chad Rosier1a1531d2012-01-26 18:24:25 +000027 %arrayidx4 = getelementptr inbounds [3 x i8*]* @fn.codetable, i32 0, i32 %2
28 br label %indirectgoto
29
30indirectgoto: ; preds = %DECREMENT, %INCREMENT, %entry
31 %result.0 = phi i32 [ 0, %entry ], [ %dec, %DECREMENT ], [ %inc, %INCREMENT ]
32 %opcodes.pn = phi i32* [ %opcodes, %entry ], [ %opcodes.addr.0, %DECREMENT ], [ %opcodes.addr.0, %INCREMENT ]
33 %indirect.goto.dest.in = phi i8** [ %arrayidx, %entry ], [ %arrayidx4, %DECREMENT ], [ %arrayidx2, %INCREMENT ]
34 %opcodes.addr.0 = getelementptr inbounds i32* %opcodes.pn, i32 1
35 %indirect.goto.dest = load i8** %indirect.goto.dest.in, align 4
36 indirectbr i8* %indirect.goto.dest, [label %RETURN, label %INCREMENT, label %DECREMENT]
37
38RETURN: ; preds = %indirectgoto
39 ret i32 %result.0
40}