3 ; These test verify that shrink-wrap does not set the restore point
4 ; to a position where the stack might still be accessed by a load or store
6 ; RUN: llc -x=mir -simplify-mir -run-pass=shrink-wrap -o - %s | FileCheck %s
7 ; CHECK: name: compiler_pop_stack
9 ; CHECK: savePoint: '%bb.1'
10 ; CHECK: restorePoint: '%bb.7'
11 ; CHECK: name: compiler_pop_stack_no_memoperands
13 ; CHECK: savePoint: '%bb.1'
14 ; CHECK: restorePoint: '%bb.7'
17 ; CHECK: savePoint: '%bb.2'
18 ; CHECK-NEXT: restorePoint: '%bb.4'
21 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
22 target triple = "aarch64"
24 %struct.S = type { i32, i32 }
26 ; Test from: https://bugs.llvm.org/show_bug.cgi?id=42136
27 define void @compiler_pop_stack(i32 %num, i32 %dec) {
29 %rstack = alloca [16 x i32], align 4
30 %idxprom = zext i32 %dec to i64
31 %arrayidx2 = getelementptr inbounds [16 x i32], ptr %rstack, i64 0, i64 %idxprom
32 %sunkaddr = mul i64 %idxprom, 4
33 %sunkaddr2 = getelementptr inbounds i8, ptr %rstack, i64 %sunkaddr
37 define void @compiler_pop_stack_no_memoperands(i32 %num, i32 %dec) {
39 %rstack = alloca [16 x i32], align 4
40 %idxprom = zext i32 %dec to i64
41 %arrayidx2 = getelementptr inbounds [16 x i32], ptr %rstack, i64 0, i64 %idxprom
42 %sunkaddr = mul i64 %idxprom, 4
43 %sunkaddr2 = getelementptr inbounds i8, ptr %rstack, i64 %sunkaddr
48 ; Test from: https://bugs.llvm.org/show_bug.cgi?id=37472
49 define i32 @f(ptr nocapture %arg, i32 %arg1) {
51 %tmp = alloca [4 x i8], align 1
52 %tmp6 = getelementptr inbounds [4 x i8], ptr %tmp, i64 0, i64 3
53 %sunkaddr = getelementptr inbounds i8, ptr %tmp, i64 3
54 %tmp14 = getelementptr inbounds %struct.S, ptr %arg, i64 0, i32 1
60 name: compiler_pop_stack
62 tracksRegLiveness: true
70 - { id: 0, name: rstack, size: 64, alignment: 4, stack-id: default, local-offset: -64 }
71 machineFunctionInfo: {}
76 dead $wzr = SUBSWri renamable $w0, 2, 0, implicit-def $nzcv
77 Bcc 3, %bb.6, implicit killed $nzcv
83 STRWui killed renamable $w0, %stack.0.rstack, 0 :: (volatile store (s32) into %ir.rstack)
84 renamable $w9 = MOVi32imm 1
85 renamable $x8 = ADDXri %stack.0.rstack, 0, 0
88 successors: %bb.3(0x30000000), %bb.4(0x50000000)
91 renamable $w10 = SUBWri renamable $w9, 1, 0, implicit-def $x10
92 renamable $w11 = LDRWroW renamable $x8, renamable $w10, 0, 1 :: (volatile load (s32) from %ir.arrayidx2)
93 CBNZW renamable $w11, %bb.4
98 renamable $w9 = COPY renamable $w10, implicit killed $x10
102 liveins: $w9, $w11, $x8, $x10
104 STRWroX killed renamable $w11, renamable $x8, killed renamable $x10, 0, 1 :: (volatile store (s32) into %ir.sunkaddr2)
107 successors: %bb.6(0x04000000), %bb.2(0x7c000000)
110 CBNZW renamable $w9, %bb.2
117 # Like compiler_pop_stack, but with the memory operands dropped from the
118 # machine instructions.
120 name: compiler_pop_stack_no_memoperands
122 tracksRegLiveness: true
130 - { id: 0, name: rstack, size: 64, alignment: 4, stack-id: default, local-offset: -64 }
131 machineFunctionInfo: {}
136 dead $wzr = SUBSWri renamable $w0, 2, 0, implicit-def $nzcv
137 Bcc 3, %bb.6, implicit killed $nzcv
143 STRWui killed renamable $w0, %stack.0.rstack, 0
144 renamable $w9 = MOVi32imm 1
145 renamable $x8 = ADDXri %stack.0.rstack, 0, 0
148 successors: %bb.3(0x30000000), %bb.4(0x50000000)
151 renamable $w10 = SUBWri renamable $w9, 1, 0, implicit-def $x10
152 renamable $w11 = LDRWroW renamable $x8, renamable $w10, 0, 1
153 CBNZW renamable $w11, %bb.4
158 renamable $w9 = COPY renamable $w10, implicit killed $x10
162 liveins: $w9, $w11, $x8, $x10
164 STRWroX killed renamable $w11, renamable $x8, killed renamable $x10, 0, 1
167 successors: %bb.6(0x04000000), %bb.2(0x7c000000)
170 CBNZW renamable $w9, %bb.2
181 tracksRegLiveness: true
190 - { id: 0, name: tmp, size: 4, alignment: 4, stack-id: default, local-offset: -4 }
191 machineFunctionInfo: {}
194 successors: %bb.1, %bb.2
197 dead $wzr = SUBSWri renamable $w1, 4, 0, implicit-def $nzcv
198 Bcc 9, %bb.2, implicit killed $nzcv
201 renamable $w0 = MOVi32imm 1
205 successors: %bb.3, %bb.4
208 renamable $w9 = MOVi32imm 67305985
209 renamable $w8 = ORRWrs $wzr, renamable $w1, 0, implicit-def $x8
210 STRWui killed renamable $w9, %stack.0.tmp, 0 :: (volatile store (s32) into %ir.tmp)
211 renamable $x9 = ADDXri %stack.0.tmp, 0, 0
212 renamable $w10 = LDRBBroX renamable $x9, renamable $x8, 0, 0 :: (volatile load (s8) from %ir.arg)
213 dead $wzr = SUBSWri killed renamable $w1, 2, 0, implicit-def $nzcv
214 STRWui killed renamable $w10, renamable $x0, 0 :: (store (s32) into %ir.arg)
215 Bcc 8, %bb.4, implicit killed $nzcv
219 liveins: $x0, $x8, $x9
221 renamable $w8 = LDRBBroX killed renamable $x9, killed renamable $x8, 0, 0 :: (volatile load (s8) from %ir.sunkaddr)
222 STRWui killed renamable $w8, killed renamable $x0, 1 :: (store (s32) into %ir.tmp14)
225 renamable $w0 = COPY $wzr
230 RET_ReallyLR implicit $w0