Add more tests for r179925 to verify correct handling of signext/zeroext; strengthen...
[oota-llvm.git] / test / CodeGen / ARM / this-return.ll
1 ; RUN: llc < %s -mtriple=armv6-linux-gnueabi -arm-tail-calls | FileCheck %s -check-prefix=CHECKELF
2 ; RUN: llc < %s -mtriple=thumbv7-apple-ios -arm-tail-calls | FileCheck %s -check-prefix=CHECKT2D
3
4 %struct.A = type { i8 }
5 %struct.B = type { i32 }
6 %struct.C = type { %struct.B }
7 %struct.D = type { %struct.B }
8 %struct.E = type { %struct.B, %struct.B }
9
10 declare %struct.A* @A_ctor_base(%struct.A* returned)
11 declare %struct.B* @B_ctor_base(%struct.B* returned, i32)
12 declare %struct.B* @B_ctor_complete(%struct.B* returned, i32)
13
14 declare %struct.A* @A_ctor_base_nothisret(%struct.A*)
15 declare %struct.B* @B_ctor_base_nothisret(%struct.B*, i32)
16 declare %struct.B* @B_ctor_complete_nothisret(%struct.B*, i32)
17
18 define %struct.C* @C_ctor_base(%struct.C* returned %this, i32 %x) {
19 entry:
20 ; CHECKELF: C_ctor_base:
21 ; CHECKELF-NOT: mov {{r[0-9]+}}, r0
22 ; CHECKELF: bl A_ctor_base
23 ; CHECKELF-NOT: mov r0, {{r[0-9]+}}
24 ; CHECKELF: b B_ctor_base
25 ; CHECKT2D: C_ctor_base:
26 ; CHECKT2D-NOT: mov {{r[0-9]+}}, r0
27 ; CHECKT2D: blx _A_ctor_base
28 ; CHECKT2D-NOT: mov r0, {{r[0-9]+}}
29 ; CHECKT2D: b.w _B_ctor_base
30   %0 = bitcast %struct.C* %this to %struct.A*
31   %call = tail call %struct.A* @A_ctor_base(%struct.A* %0)
32   %1 = getelementptr inbounds %struct.C* %this, i32 0, i32 0
33   %call2 = tail call %struct.B* @B_ctor_base(%struct.B* %1, i32 %x)
34   ret %struct.C* %this
35 }
36
37 define %struct.C* @C_ctor_base_nothisret(%struct.C* %this, i32 %x) {
38 entry:
39 ; CHECKELF: C_ctor_base_nothisret:
40 ; CHECKELF: mov [[SAVETHIS:r[0-9]+]], r0
41 ; CHECKELF: bl A_ctor_base_nothisret
42 ; CHECKELF: mov r0, [[SAVETHIS]]
43 ; CHECKELF-NOT: b B_ctor_base_nothisret
44 ; CHECKT2D: C_ctor_base_nothisret:
45 ; CHECKT2D: mov [[SAVETHIS:r[0-9]+]], r0
46 ; CHECKT2D: blx _A_ctor_base_nothisret
47 ; CHECKT2D: mov r0, [[SAVETHIS]]
48 ; CHECKT2D-NOT: b.w _B_ctor_base_nothisret
49   %0 = bitcast %struct.C* %this to %struct.A*
50   %call = tail call %struct.A* @A_ctor_base_nothisret(%struct.A* %0)
51   %1 = getelementptr inbounds %struct.C* %this, i32 0, i32 0
52   %call2 = tail call %struct.B* @B_ctor_base_nothisret(%struct.B* %1, i32 %x)
53   ret %struct.C* %this
54 }
55
56 define %struct.C* @C_ctor_complete(%struct.C* %this, i32 %x) {
57 entry:
58 ; CHECKELF: C_ctor_complete:
59 ; CHECKELF: b C_ctor_base
60 ; CHECKT2D: C_ctor_complete:
61 ; CHECKT2D: b.w _C_ctor_base
62   %call = tail call %struct.C* @C_ctor_base(%struct.C* %this, i32 %x)
63   ret %struct.C* %this
64 }
65
66 define %struct.C* @C_ctor_complete_nothisret(%struct.C* %this, i32 %x) {
67 entry:
68 ; CHECKELF: C_ctor_complete_nothisret:
69 ; CHECKELF-NOT: b C_ctor_base_nothisret
70 ; CHECKT2D: C_ctor_complete_nothisret:
71 ; CHECKT2D-NOT: b.w _C_ctor_base_nothisret
72   %call = tail call %struct.C* @C_ctor_base_nothisret(%struct.C* %this, i32 %x)
73   ret %struct.C* %this
74 }
75
76 define %struct.D* @D_ctor_base(%struct.D* %this, i32 %x) {
77 entry:
78 ; CHECKELF: D_ctor_base:
79 ; CHECKELF-NOT: mov {{r[0-9]+}}, r0
80 ; CHECKELF: bl B_ctor_complete
81 ; CHECKELF-NOT: mov r0, {{r[0-9]+}}
82 ; CHECKELF: b B_ctor_complete
83 ; CHECKT2D: D_ctor_base:
84 ; CHECKT2D-NOT: mov {{r[0-9]+}}, r0
85 ; CHECKT2D: blx _B_ctor_complete
86 ; CHECKT2D-NOT: mov r0, {{r[0-9]+}}
87 ; CHECKT2D: b.w _B_ctor_complete
88   %b = getelementptr inbounds %struct.D* %this, i32 0, i32 0
89   %call = tail call %struct.B* @B_ctor_complete(%struct.B* %b, i32 %x)
90   %call2 = tail call %struct.B* @B_ctor_complete(%struct.B* %b, i32 %x)
91   ret %struct.D* %this
92 }
93
94 define %struct.E* @E_ctor_base(%struct.E* %this, i32 %x) {
95 entry:
96 ; CHECKELF: E_ctor_base:
97 ; CHECKELF-NOT: b B_ctor_complete
98 ; CHECKT2D: E_ctor_base:
99 ; CHECKT2D-NOT: b.w _B_ctor_complete
100   %b = getelementptr inbounds %struct.E* %this, i32 0, i32 0
101   %call = tail call %struct.B* @B_ctor_complete(%struct.B* %b, i32 %x)
102   %b2 = getelementptr inbounds %struct.E* %this, i32 0, i32 1
103   %call2 = tail call %struct.B* @B_ctor_complete(%struct.B* %b2, i32 %x)
104   ret %struct.E* %this
105 }
106
107 declare i16 @identity16(i16 returned %x)
108 declare zeroext i16 @zeroext16(i16 returned %x)
109 declare i32 @identity32(i32 returned %x)
110
111 define i16 @test_identity(i16 %x) {
112 entry:
113 ; CHECKELF: test_identity:
114 ; CHECKELF: mov [[SAVEX:r[0-9]+]], r0
115 ; CHECKELF: bl identity16
116 ; CHECKELF: uxth r0, [[SAVEX]]
117 ; CHECKELF: bl identity32
118 ; CHECKELF: mov r0, [[SAVEX]]
119 ; CHECKT2D: test_identity:
120 ; CHECKT2D: mov [[SAVEX:r[0-9]+]], r0
121 ; CHECKT2D: blx _identity16
122 ; CHECKT2D: uxth r0, [[SAVEX]]
123 ; CHECKT2D: blx _identity32
124 ; CHECKT2D: mov r0, [[SAVEX]]
125   %call = tail call i16 @identity16(i16 %x)
126   %b = zext i16 %x to i32
127   %call2 = tail call i32 @identity32(i32 %b)
128   ret i16 %call
129 }
130
131 define i16 @test_matched_ext(i16 %x) {
132 entry:
133 ; CHECKELF: test_matched_ext:
134 ; CHECKELF-NOT: mov {{r[0-9]+}}, r0
135 ; CHECKELF: bl zeroext16
136 ; CHECKELF-NOT: uxth r0, {{r[0-9]+}}
137 ; CHECKELF: bl identity32
138 ; CHECKELF-NOT: mov r0, {{r[0-9]+}}
139 ; CHECKT2D: test_matched_ext:
140 ; CHECKT2D-NOT: mov {{r[0-9]+}}, r0
141 ; CHECKT2D: blx _zeroext16
142 ; CHECKT2D-NOT: uxth r0, {{r[0-9]+}}
143 ; CHECKT2D: blx _identity32
144 ; CHECKT2D-NOT: mov r0, {{r[0-9]+}}
145   %call = tail call i16 @zeroext16(i16 %x)
146   %b = zext i16 %call to i32
147   %call2 = tail call i32 @identity32(i32 %b)
148   ret i16 %call
149 }
150
151 define i16 @test_mismatched_ext(i16 %x) {
152 entry:
153 ; CHECKELF: test_mismatched_ext:
154 ; CHECKELF: mov [[SAVEX:r[0-9]+]], r0
155 ; CHECKELF: bl zeroext16
156 ; CHECKELF: sxth r0, [[SAVEX]]
157 ; CHECKELF: bl identity32
158 ; CHECKELF: mov r0, [[SAVEX]]
159 ; CHECKT2D: test_mismatched_ext:
160 ; CHECKT2D: mov [[SAVEX:r[0-9]+]], r0
161 ; CHECKT2D: blx _zeroext16
162 ; CHECKT2D: sxth r0, [[SAVEX]]
163 ; CHECKT2D: blx _identity32
164 ; CHECKT2D: mov r0, [[SAVEX]]
165   %call = tail call i16 @zeroext16(i16 %x)
166   %b = sext i16 %call to i32
167   %call2 = tail call i32 @identity32(i32 %b)
168   ret i16 %call
169 }