xref: /aosp_15_r20/external/llvm/test/CodeGen/Mips/cconv/arguments-hard-float-varargs.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mips -relocation-model=static < %s | FileCheck --check-prefixes=ALL,SYM32,O32,O32BE %s
2*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mipsel -relocation-model=static < %s | FileCheck --check-prefixes=ALL,SYM32,O32,O32LE %s
3*9880d681SAndroid Build Coastguard Worker
4*9880d681SAndroid Build Coastguard Worker; RUN-TODO: llc -march=mips64 -relocation-model=static -target-abi o32 < %s | FileCheck --check-prefixes=ALL,SYM32,O32 %s
5*9880d681SAndroid Build Coastguard Worker; RUN-TODO: llc -march=mips64el -relocation-model=static -target-abi o32 < %s | FileCheck --check-prefixes=ALL,SYM32,O32 %s
6*9880d681SAndroid Build Coastguard Worker
7*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mips64 -relocation-model=static -target-abi n32 < %s | FileCheck --check-prefixes=ALL,SYM32,N32,NEW,NEWBE %s
8*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mips64el -relocation-model=static -target-abi n32 < %s | FileCheck --check-prefixes=ALL,SYM32,N32,NEW,NEWLE %s
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mips64 -relocation-model=static -target-abi n64 < %s | FileCheck --check-prefixes=ALL,SYM64,N64,NEW,NEWBE %s
11*9880d681SAndroid Build Coastguard Worker; RUN: llc -march=mips64el -relocation-model=static -target-abi n64 < %s | FileCheck --check-prefixes=ALL,SYM64,N64,NEW,NEWLE %s
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker; Test the effect of varargs on floating point types in the non-variable part
14*9880d681SAndroid Build Coastguard Worker; of the argument list as specified by section 2 of the MIPSpro N32 Handbook.
15*9880d681SAndroid Build Coastguard Worker;
16*9880d681SAndroid Build Coastguard Worker; N32/N64 are almost identical in this area so many of their checks have been
17*9880d681SAndroid Build Coastguard Worker; combined into the 'NEW' prefix (the N stands for New).
18*9880d681SAndroid Build Coastguard Worker;
19*9880d681SAndroid Build Coastguard Worker; On O32, varargs prevents all FPU argument register usage. This contradicts
20*9880d681SAndroid Build Coastguard Worker; the N32 handbook, but agrees with the SYSV ABI and GCC's behaviour.
21*9880d681SAndroid Build Coastguard Worker
22*9880d681SAndroid Build Coastguard Worker@floats = global [11 x float] zeroinitializer
23*9880d681SAndroid Build Coastguard Worker@doubles = global [11 x double] zeroinitializer
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Workerdefine void @double_args(double %a, ...)
26*9880d681SAndroid Build Coastguard Worker                         nounwind {
27*9880d681SAndroid Build Coastguard Workerentry:
28*9880d681SAndroid Build Coastguard Worker        %0 = getelementptr [11 x double], [11 x double]* @doubles, i32 0, i32 1
29*9880d681SAndroid Build Coastguard Worker        store volatile double %a, double* %0
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Worker        %ap = alloca i8*
32*9880d681SAndroid Build Coastguard Worker        %ap2 = bitcast i8** %ap to i8*
33*9880d681SAndroid Build Coastguard Worker        call void @llvm.va_start(i8* %ap2)
34*9880d681SAndroid Build Coastguard Worker        %b = va_arg i8** %ap, double
35*9880d681SAndroid Build Coastguard Worker        %1 = getelementptr [11 x double], [11 x double]* @doubles, i32 0, i32 2
36*9880d681SAndroid Build Coastguard Worker        store volatile double %b, double* %1
37*9880d681SAndroid Build Coastguard Worker        call void @llvm.va_end(i8* %ap2)
38*9880d681SAndroid Build Coastguard Worker        ret void
39*9880d681SAndroid Build Coastguard Worker}
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Worker; ALL-LABEL: double_args:
42*9880d681SAndroid Build Coastguard Worker; We won't test the way the global address is calculated in this test. This is
43*9880d681SAndroid Build Coastguard Worker; just to get the register number for the other checks.
44*9880d681SAndroid Build Coastguard Worker; SYM32-DAG:         addiu [[R2:\$[0-9]+]], ${{[0-9]+}}, %lo(doubles)
45*9880d681SAndroid Build Coastguard Worker; SYM64-DAG:         ld [[R2:\$[0-9]]], %got_disp(doubles)(
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker; O32 forbids using floating point registers for the non-variable portion.
48*9880d681SAndroid Build Coastguard Worker; N32/N64 allow it.
49*9880d681SAndroid Build Coastguard Worker; O32BE-DAG:         mtc1 $5, [[FTMP1:\$f[0-9]*[02468]+]]
50*9880d681SAndroid Build Coastguard Worker; O32BE-DAG:         mtc1 $4, [[FTMP2:\$f[0-9]*[13579]+]]
51*9880d681SAndroid Build Coastguard Worker; O32LE-DAG:         mtc1 $4, [[FTMP1:\$f[0-9]*[02468]+]]
52*9880d681SAndroid Build Coastguard Worker; O32LE-DAG:         mtc1 $5, [[FTMP2:\$f[0-9]*[13579]+]]
53*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sdc1 [[FTMP1]], 8([[R2]])
54*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sdc1 $f12, 8([[R2]])
55*9880d681SAndroid Build Coastguard Worker
56*9880d681SAndroid Build Coastguard Worker; The varargs portion is dumped to stack
57*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sw $6, 16($sp)
58*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sw $7, 20($sp)
59*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $5, 8($sp)
60*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $6, 16($sp)
61*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $7, 24($sp)
62*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $8, 32($sp)
63*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $9, 40($sp)
64*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $10, 48($sp)
65*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $11, 56($sp)
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Worker; Get the varargs pointer
68*9880d681SAndroid Build Coastguard Worker; O32 has 4 bytes padding, 4 bytes for the varargs pointer, and 8 bytes reserved
69*9880d681SAndroid Build Coastguard Worker; for arguments 1 and 2.
70*9880d681SAndroid Build Coastguard Worker; N32/N64 has 8 bytes for the varargs pointer, and no reserved area.
71*9880d681SAndroid Build Coastguard Worker; O32-DAG:           addiu [[VAPTR:\$[0-9]+]], $sp, 16
72*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sw [[VAPTR]], 4($sp)
73*9880d681SAndroid Build Coastguard Worker; N32-DAG:           addiu [[VAPTR:\$[0-9]+]], $sp, 8
74*9880d681SAndroid Build Coastguard Worker; N32-DAG:           sw [[VAPTR]], 4($sp)
75*9880d681SAndroid Build Coastguard Worker; N64-DAG:           daddiu [[VAPTR:\$[0-9]+]], $sp, 8
76*9880d681SAndroid Build Coastguard Worker; N64-DAG:           sd [[VAPTR]], 0($sp)
77*9880d681SAndroid Build Coastguard Worker
78*9880d681SAndroid Build Coastguard Worker; Increment the pointer then get the varargs arg
79*9880d681SAndroid Build Coastguard Worker; LLVM will rebind the load to the stack pointer instead of the varargs pointer
80*9880d681SAndroid Build Coastguard Worker; during lowering. This is fine and doesn't change the behaviour.
81*9880d681SAndroid Build Coastguard Worker; O32-DAG:           addiu [[VAPTR]], [[VAPTR]], 8
82*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sw [[VAPTR]], 4($sp)
83*9880d681SAndroid Build Coastguard Worker; N32-DAG:           addiu [[VAPTR]], [[VAPTR]], 8
84*9880d681SAndroid Build Coastguard Worker; N32-DAG:           sw [[VAPTR]], 4($sp)
85*9880d681SAndroid Build Coastguard Worker; N64-DAG:           daddiu [[VAPTR]], [[VAPTR]], 8
86*9880d681SAndroid Build Coastguard Worker; N64-DAG:           sd [[VAPTR]], 0($sp)
87*9880d681SAndroid Build Coastguard Worker; O32-DAG:           ldc1 [[FTMP1:\$f[0-9]+]], 16($sp)
88*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           ldc1 [[FTMP1:\$f[0-9]+]], 8($sp)
89*9880d681SAndroid Build Coastguard Worker; ALL-DAG:           sdc1 [[FTMP1]], 16([[R2]])
90*9880d681SAndroid Build Coastguard Worker
91*9880d681SAndroid Build Coastguard Workerdefine void @float_args(float %a, ...) nounwind {
92*9880d681SAndroid Build Coastguard Workerentry:
93*9880d681SAndroid Build Coastguard Worker        %0 = getelementptr [11 x float], [11 x float]* @floats, i32 0, i32 1
94*9880d681SAndroid Build Coastguard Worker        store volatile float %a, float* %0
95*9880d681SAndroid Build Coastguard Worker
96*9880d681SAndroid Build Coastguard Worker        %ap = alloca i8*
97*9880d681SAndroid Build Coastguard Worker        %ap2 = bitcast i8** %ap to i8*
98*9880d681SAndroid Build Coastguard Worker        call void @llvm.va_start(i8* %ap2)
99*9880d681SAndroid Build Coastguard Worker        %b = va_arg i8** %ap, float
100*9880d681SAndroid Build Coastguard Worker        %1 = getelementptr [11 x float], [11 x float]* @floats, i32 0, i32 2
101*9880d681SAndroid Build Coastguard Worker        store volatile float %b, float* %1
102*9880d681SAndroid Build Coastguard Worker        call void @llvm.va_end(i8* %ap2)
103*9880d681SAndroid Build Coastguard Worker        ret void
104*9880d681SAndroid Build Coastguard Worker}
105*9880d681SAndroid Build Coastguard Worker
106*9880d681SAndroid Build Coastguard Worker; ALL-LABEL: float_args:
107*9880d681SAndroid Build Coastguard Worker; We won't test the way the global address is calculated in this test. This is
108*9880d681SAndroid Build Coastguard Worker; just to get the register number for the other checks.
109*9880d681SAndroid Build Coastguard Worker; SYM32-DAG:         addiu [[R2:\$[0-9]+]], ${{[0-9]+}}, %lo(floats)
110*9880d681SAndroid Build Coastguard Worker; SYM64-DAG:         ld [[R2:\$[0-9]]], %got_disp(floats)(
111*9880d681SAndroid Build Coastguard Worker
112*9880d681SAndroid Build Coastguard Worker; The first four arguments are the same in O32/N32/N64.
113*9880d681SAndroid Build Coastguard Worker; The non-variable portion should be unaffected.
114*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sw $4, 4([[R2]])
115*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           swc1 $f12, 4([[R2]])
116*9880d681SAndroid Build Coastguard Worker
117*9880d681SAndroid Build Coastguard Worker; The varargs portion is dumped to stack
118*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sw $5, 12($sp)
119*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sw $6, 16($sp)
120*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sw $7, 20($sp)
121*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $5, 8($sp)
122*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $6, 16($sp)
123*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $7, 24($sp)
124*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $8, 32($sp)
125*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $9, 40($sp)
126*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $10, 48($sp)
127*9880d681SAndroid Build Coastguard Worker; NEW-DAG:           sd $11, 56($sp)
128*9880d681SAndroid Build Coastguard Worker
129*9880d681SAndroid Build Coastguard Worker; Get the varargs pointer
130*9880d681SAndroid Build Coastguard Worker; O32 has 4 bytes padding, 4 bytes for the varargs pointer, and should have 8
131*9880d681SAndroid Build Coastguard Worker; bytes reserved for arguments 1 and 2 (the first float arg) but as discussed in
132*9880d681SAndroid Build Coastguard Worker; arguments-float.ll, GCC doesn't agree with MD00305 and treats floats as 4
133*9880d681SAndroid Build Coastguard Worker; bytes so we only have 12 bytes total.
134*9880d681SAndroid Build Coastguard Worker; N32/N64 has 8 bytes for the varargs pointer, and no reserved area.
135*9880d681SAndroid Build Coastguard Worker; O32-DAG:           addiu [[VAPTR:\$[0-9]+]], $sp, 12
136*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sw [[VAPTR]], 4($sp)
137*9880d681SAndroid Build Coastguard Worker; N32-DAG:           addiu [[VAPTR:\$[0-9]+]], $sp, 8
138*9880d681SAndroid Build Coastguard Worker; N32-DAG:           sw [[VAPTR]], 4($sp)
139*9880d681SAndroid Build Coastguard Worker; N64-DAG:           daddiu [[VAPTR:\$[0-9]+]], $sp, 8
140*9880d681SAndroid Build Coastguard Worker; N64-DAG:           sd [[VAPTR]], 0($sp)
141*9880d681SAndroid Build Coastguard Worker
142*9880d681SAndroid Build Coastguard Worker; Increment the pointer then get the varargs arg
143*9880d681SAndroid Build Coastguard Worker; LLVM will rebind the load to the stack pointer instead of the varargs pointer
144*9880d681SAndroid Build Coastguard Worker; during lowering. This is fine and doesn't change the behaviour.
145*9880d681SAndroid Build Coastguard Worker; Also, in big-endian mode the offset must be increased by 4 to retrieve the
146*9880d681SAndroid Build Coastguard Worker; correct half of the argument slot.
147*9880d681SAndroid Build Coastguard Worker;
148*9880d681SAndroid Build Coastguard Worker; O32-DAG:           addiu [[VAPTR]], [[VAPTR]], 4
149*9880d681SAndroid Build Coastguard Worker; O32-DAG:           sw [[VAPTR]], 4($sp)
150*9880d681SAndroid Build Coastguard Worker; N32-DAG:           addiu [[VAPTR]], [[VAPTR]], 8
151*9880d681SAndroid Build Coastguard Worker; N32-DAG:           sw [[VAPTR]], 4($sp)
152*9880d681SAndroid Build Coastguard Worker; N64-DAG:           daddiu [[VAPTR]], [[VAPTR]], 8
153*9880d681SAndroid Build Coastguard Worker; N64-DAG:           sd [[VAPTR]], 0($sp)
154*9880d681SAndroid Build Coastguard Worker; O32-DAG:           lwc1 [[FTMP1:\$f[0-9]+]], 12($sp)
155*9880d681SAndroid Build Coastguard Worker; NEWLE-DAG:         lwc1 [[FTMP1:\$f[0-9]+]], 8($sp)
156*9880d681SAndroid Build Coastguard Worker; NEWBE-DAG:         lwc1 [[FTMP1:\$f[0-9]+]], 12($sp)
157*9880d681SAndroid Build Coastguard Worker; ALL-DAG:           swc1 [[FTMP1]], 8([[R2]])
158*9880d681SAndroid Build Coastguard Worker
159*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.va_start(i8*)
160*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.va_copy(i8*, i8*)
161*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.va_end(i8*)
162