[mips] Add capability to search in the forward direction for instructions that
[oota-llvm.git] / test / CodeGen / Mips / brdelayslot.ll
1 ; RUN: llc -march=mipsel -O0 < %s | FileCheck %s -check-prefix=None
2 ; RUN: llc -march=mipsel < %s | FileCheck %s -check-prefix=Default
3 ; RUN: llc -march=mipsel -O1 -relocation-model=static < %s | \
4 ; RUN: FileCheck %s -check-prefix=STATICO1
5 ; RUN: llc -march=mipsel -disable-mips-df-forward-search=false \
6 ; RUN: -relocation-model=static < %s | FileCheck %s -check-prefix=FORWARD
7
8 define void @foo1() nounwind {
9 entry:
10 ; Default:     jalr 
11 ; Default-NOT: nop 
12 ; Default:     jr 
13 ; Default-NOT: nop
14 ; Default:     .end
15 ; None: jalr 
16 ; None: nop 
17 ; None: jr 
18 ; None: nop
19 ; None: .end
20
21   tail call void @foo2(i32 3) nounwind
22   ret void
23 }
24
25 declare void @foo2(i32)
26
27 ; Check that cvt.d.w goes into jalr's delay slot.
28 ;
29 define void @foo3(i32 %a) nounwind {
30 entry:
31 ; Default:     foo3:
32 ; Default:     jalr
33 ; Default:     cvt.d.w
34
35   %conv = sitofp i32 %a to double
36   tail call void @foo4(double %conv) nounwind
37   ret void
38 }
39
40 declare void @foo4(double)
41
42 @g2 = external global i32
43 @g1 = external global i32
44 @g3 = external global i32
45
46 ; Check that branch delay slot can be filled with an instruction with operand
47 ; $1.
48 ;
49 ; Default:     foo5:
50 ; Default-NOT: nop
51
52 define void @foo5(i32 %a) nounwind {
53 entry:
54   %0 = load i32* @g2, align 4
55   %tobool = icmp eq i32 %a, 0
56   br i1 %tobool, label %if.else, label %if.then
57
58 if.then:
59   %1 = load i32* @g1, align 4
60   %add = add nsw i32 %1, %0
61   store i32 %add, i32* @g1, align 4
62   br label %if.end
63
64 if.else:
65   %2 = load i32* @g3, align 4
66   %sub = sub nsw i32 %2, %0
67   store i32 %sub, i32* @g3, align 4
68   br label %if.end
69
70 if.end:
71   ret void
72 }
73
74 ; Check that delay slot filler can place mov.s or mov.d in delay slot.
75 ;
76 ; Default:     foo6:
77 ; Default-NOT: nop
78
79 define void @foo6(float %a0, double %a1) nounwind {
80 entry:
81   tail call void @foo7(double %a1, float %a0) nounwind
82   ret void
83 }
84
85 declare void @foo7(double, float)
86
87 ; Check that a store can move past other memory instructions.
88 ;
89 ; STATICO1:      foo8:
90 ; STATICO1:      jalr ${{[0-9]+}}
91 ; STATICO1-NEXT: sw ${{[0-9]+}}, %lo(g1)
92
93 @foo9 = common global void ()* null, align 4
94
95 define i32 @foo8(i32 %a) nounwind {
96 entry:
97   store i32 %a, i32* @g1, align 4
98   %0 = load void ()** @foo9, align 4
99   tail call void %0() nounwind
100   %1 = load i32* @g1, align 4
101   %add = add nsw i32 %1, %a
102   ret i32 %add
103 }
104
105 ; Test searchForward. Check that the second jal's slot is filled with another
106 ; instruction in the same block.
107 ;
108 ; FORWARD:     foo10:
109 ; FORWARD:     jal foo11
110 ; FORWARD:     jal foo11
111 ; FORWARD-NOT: nop
112
113 define void @foo10() nounwind {
114 entry:
115   tail call void @foo11() nounwind
116   tail call void @foo11() nounwind
117   store i32 0, i32* @g1, align 4
118   tail call void @foo11() nounwind
119   store i32 0, i32* @g1, align 4
120   ret void
121 }
122
123 declare void @foo11()