xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/stack-align.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -relocation-model=static -mcpu=yonah | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Worker; The double argument is at 4(esp) which is 16-byte aligned, but we
4*9880d681SAndroid Build Coastguard Worker; are required to read in extra bytes of memory in order to fold the
5*9880d681SAndroid Build Coastguard Worker; load. Bad Things may happen when reading/processing undefined bytes,
6*9880d681SAndroid Build Coastguard Worker; so don't fold the load.
7*9880d681SAndroid Build Coastguard Worker; PR22371 / http://reviews.llvm.org/D7474
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
10*9880d681SAndroid Build Coastguard Workertarget triple = "i686-apple-darwin8"
11*9880d681SAndroid Build Coastguard Worker@G = external global double
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Workerdefine void @test({ double, double }* byval  %z, double* %P) nounwind {
14*9880d681SAndroid Build Coastguard Workerentry:
15*9880d681SAndroid Build Coastguard Worker	%tmp3 = load double, double* @G, align 16		; <double> [#uses=1]
16*9880d681SAndroid Build Coastguard Worker	%tmp4 = tail call double @fabs( double %tmp3 ) readnone	; <double> [#uses=1]
17*9880d681SAndroid Build Coastguard Worker        store volatile double %tmp4, double* %P
18*9880d681SAndroid Build Coastguard Worker	%tmp = getelementptr { double, double }, { double, double }* %z, i32 0, i32 0		; <double*> [#uses=1]
19*9880d681SAndroid Build Coastguard Worker	%tmp1 = load volatile double, double* %tmp, align 8		; <double> [#uses=1]
20*9880d681SAndroid Build Coastguard Worker	%tmp2 = tail call double @fabs( double %tmp1 ) readnone	; <double> [#uses=1]
21*9880d681SAndroid Build Coastguard Worker	%tmp6 = fadd double %tmp4, %tmp2		; <double> [#uses=1]
22*9880d681SAndroid Build Coastguard Worker	store volatile double %tmp6, double* %P, align 8
23*9880d681SAndroid Build Coastguard Worker	ret void
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test:
26*9880d681SAndroid Build Coastguard Worker; CHECK:       movsd	{{.*}}G, %xmm{{.*}}
27*9880d681SAndroid Build Coastguard Worker; CHECK:       andpd	%xmm{{.*}}, %xmm{{.*}}
28*9880d681SAndroid Build Coastguard Worker; CHECK:       movsd	4(%esp), %xmm{{.*}}
29*9880d681SAndroid Build Coastguard Worker; CHECK:       andpd	%xmm{{.*}}, %xmm{{.*}}
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Worker
32*9880d681SAndroid Build Coastguard Worker}
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Workerdefine void @test2() alignstack(16) nounwind {
35*9880d681SAndroid Build Coastguard Workerentry:
36*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test2:
37*9880d681SAndroid Build Coastguard Worker; CHECK: andl{{.*}}$-16, %esp
38*9880d681SAndroid Build Coastguard Worker    ret void
39*9880d681SAndroid Build Coastguard Worker}
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Worker; Use a call to force a spill.
42*9880d681SAndroid Build Coastguard Workerdefine <2 x double> @test3(<2 x double> %x, <2 x double> %y) alignstack(32) nounwind {
43*9880d681SAndroid Build Coastguard Workerentry:
44*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test3:
45*9880d681SAndroid Build Coastguard Worker; CHECK: andl{{.*}}$-32, %esp
46*9880d681SAndroid Build Coastguard Worker    call void @test2()
47*9880d681SAndroid Build Coastguard Worker    %A = fmul <2 x double> %x, %y
48*9880d681SAndroid Build Coastguard Worker    ret <2 x double> %A
49*9880d681SAndroid Build Coastguard Worker}
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Workerdeclare double @fabs(double)
52*9880d681SAndroid Build Coastguard Worker
53*9880d681SAndroid Build Coastguard Worker; The pointer is already known aligned, so and x,-16 is eliminable.
54*9880d681SAndroid Build Coastguard Workerdefine i32 @test4() nounwind {
55*9880d681SAndroid Build Coastguard Workerentry:
56*9880d681SAndroid Build Coastguard Worker  %buffer = alloca [2048 x i8], align 16
57*9880d681SAndroid Build Coastguard Worker  %0 = ptrtoint [2048 x i8]* %buffer to i32
58*9880d681SAndroid Build Coastguard Worker  %and = and i32 %0, -16
59*9880d681SAndroid Build Coastguard Worker  ret i32 %and
60*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test4:
61*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: and
62*9880d681SAndroid Build Coastguard Worker; CHECK: ret
63*9880d681SAndroid Build Coastguard Worker}
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Worker%struct.sixteen = type { [16 x i8] }
66*9880d681SAndroid Build Coastguard Worker
67*9880d681SAndroid Build Coastguard Worker; Accessing stack parameters shouldn't assume stack alignment. Here we should
68*9880d681SAndroid Build Coastguard Worker; emit two 8-byte loads, followed by two 8-byte stores.
69*9880d681SAndroid Build Coastguard Workerdefine x86_stdcallcc void @test5(%struct.sixteen* byval nocapture readonly align 4 %s) #0 {
70*9880d681SAndroid Build Coastguard Worker  %d.sroa.0 = alloca [16 x i8], align 1
71*9880d681SAndroid Build Coastguard Worker  %1 = getelementptr inbounds [16 x i8], [16 x i8]* %d.sroa.0, i32 0, i32 0
72*9880d681SAndroid Build Coastguard Worker  call void @llvm.lifetime.start(i64 16, i8* %1)
73*9880d681SAndroid Build Coastguard Worker  %2 = getelementptr inbounds %struct.sixteen, %struct.sixteen* %s, i32 0, i32 0, i32 0
74*9880d681SAndroid Build Coastguard Worker  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %1, i8* %2, i32 16, i32 1, i1 true)
75*9880d681SAndroid Build Coastguard Worker  call void @llvm.lifetime.end(i64 16, i8* %1)
76*9880d681SAndroid Build Coastguard Worker  ret void
77*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: test5:
78*9880d681SAndroid Build Coastguard Worker; CHECK: and
79*9880d681SAndroid Build Coastguard Worker; CHECK: movsd
80*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movsd
81*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movsd
82*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movsd
83*9880d681SAndroid Build Coastguard Worker}
84*9880d681SAndroid Build Coastguard Worker
85*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.lifetime.start(i64, i8* nocapture) argmemonly nounwind
86*9880d681SAndroid Build Coastguard Worker
87*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i32, i1) argmemonly nounwind
88*9880d681SAndroid Build Coastguard Worker
89*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.lifetime.end(i64, i8* nocapture) argmemonly nounwind
90*9880d681SAndroid Build Coastguard Worker
91*9880d681SAndroid Build Coastguard Workerattributes #0 = { nounwind alignstack=16 "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" }
92