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-NOT: savePoint:
10 ; CHECK-NOT: restorePoint:
14 ; CHECK: savePoint: '%bb.2'
15 ; CHECK-NEXT: restorePoint: '%bb.4'
18 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
19 target triple = "aarch64-arm-none-eabi"
21 %struct.S = type { i32, i32 }
23 @__const.f.arr = private unnamed_addr constant [4 x i8] c"\01\02\03\04", align 1
26 declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture)
29 declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture)
32 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1 immarg)
33 ; Test from: https://bugs.llvm.org/show_bug.cgi?id=42136
34 define void @compiler_pop_stack(i32 %num) {
36 %rstack = alloca [16 x i32], align 4
37 %tmp = bitcast [16 x i32]* %rstack to i8*
38 call void @llvm.lifetime.start.p0i8(i64 64, i8* nonnull %tmp)
39 %cmp = icmp ult i32 %num, 2
40 br i1 %cmp, label %cleanup, label %if.end
43 %arrayidx1 = bitcast [16 x i32]* %rstack to i32*
44 store volatile i32 %num, i32* %arrayidx1, align 4
48 %ptr.017 = phi i32 [ 1, %if.end ], [ %ptr.1, %if.end7 ]
49 %dec = add i32 %ptr.017, -1
50 %idxprom = zext i32 %dec to i64
51 %arrayidx2 = getelementptr inbounds [16 x i32], [16 x i32]* %rstack, i64 0, i64 %idxprom
52 %tmp1 = load volatile i32, i32* %arrayidx2, align 4
53 %cmp3 = icmp eq i32 %tmp1, 0
54 br i1 %cmp3, label %if.end7, label %if.then4
57 %sunkaddr = mul i64 %idxprom, 4
58 %0 = bitcast [16 x i32]* %rstack to i8*
59 %sunkaddr2 = getelementptr inbounds i8, i8* %0, i64 %sunkaddr
60 %1 = bitcast i8* %sunkaddr2 to i32*
61 store volatile i32 %tmp1, i32* %1, align 4
65 %ptr.1 = phi i32 [ %ptr.017, %if.then4 ], [ %dec, %while.body ]
66 %cmp1 = icmp eq i32 %ptr.1, 0
67 br i1 %cmp1, label %cleanup, label %while.body
70 %2 = bitcast [16 x i32]* %rstack to i8*
71 call void @llvm.lifetime.end.p0i8(i64 64, i8* nonnull %2)
74 ; Test from: https://bugs.llvm.org/show_bug.cgi?id=37472
75 define i32 @f(%struct.S* nocapture %arg, i32 %arg1) {
77 %tmp = alloca [4 x i8], align 1
78 %tmp2 = icmp ugt i32 %arg1, 4
79 br i1 %tmp2, label %bb16, label %bb3
82 %tmp41 = bitcast [4 x i8]* %tmp to i8*
83 call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %tmp41)
84 call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 1 %tmp41, i8* align 1 getelementptr inbounds ([4 x i8], [4 x i8]* @__const.f.arr, i64 0, i64 0), i64 4, i1 true)
85 %tmp5 = zext i32 %arg1 to i64
86 %tmp6 = getelementptr inbounds [4 x i8], [4 x i8]* %tmp, i64 0, i64 %tmp5
87 %tmp7 = load volatile i8, i8* %tmp6, align 1
88 %tmp8 = zext i8 %tmp7 to i32
89 %tmp92 = bitcast %struct.S* %arg to i32*
90 store i32 %tmp8, i32* %tmp92, align 4
91 %tmp10 = icmp ult i32 %arg1, 3
92 br i1 %tmp10, label %bb11, label %bb15
95 %0 = bitcast [4 x i8]* %tmp to i8*
96 %sunkaddr = getelementptr inbounds i8, i8* %0, i64 %tmp5
97 %tmp12 = load volatile i8, i8* %sunkaddr, align 1
98 %tmp13 = zext i8 %tmp12 to i32
99 %tmp14 = getelementptr inbounds %struct.S, %struct.S* %arg, i64 0, i32 1
100 store i32 %tmp13, i32* %tmp14, align 4
104 %1 = bitcast [4 x i8]* %tmp to i8*
105 call void @llvm.lifetime.end.p0i8(i64 4, i8* nonnull %1)
109 %tmp17 = phi i32 [ 0, %bb15 ], [ 1, %bb ]
114 declare void @llvm.stackprotector(i8*, i8**)
118 name: compiler_pop_stack
120 tracksRegLiveness: true
128 - { id: 0, name: rstack, size: 64, alignment: 4, stack-id: default, local-offset: -64 }
129 machineFunctionInfo: {}
134 dead $wzr = SUBSWri renamable $w0, 2, 0, implicit-def $nzcv
135 Bcc 3, %bb.6, implicit killed $nzcv
141 STRWui killed renamable $w0, %stack.0.rstack, 0 :: (volatile store 4 into %ir.arrayidx1)
142 renamable $w9 = MOVi32imm 1
143 renamable $x8 = ADDXri %stack.0.rstack, 0, 0
146 successors: %bb.3(0x30000000), %bb.4(0x50000000)
149 renamable $w10 = SUBWri renamable $w9, 1, 0, implicit-def $x10
150 renamable $w11 = LDRWroW renamable $x8, renamable $w10, 0, 1 :: (volatile load 4 from %ir.arrayidx2)
151 CBNZW renamable $w11, %bb.4
156 renamable $w9 = COPY renamable $w10, implicit killed $x10
160 liveins: $w9, $w11, $x8, $x10
162 STRWroX killed renamable $w11, renamable $x8, killed renamable $x10, 0, 1 :: (volatile store 4 into %ir.1)
165 successors: %bb.6(0x04000000), %bb.2(0x7c000000)
168 CBNZW renamable $w9, %bb.2
178 tracksRegLiveness: true
187 - { id: 0, name: tmp, size: 4, alignment: 4, stack-id: default, local-offset: -4 }
188 machineFunctionInfo: {}
191 successors: %bb.1, %bb.2
194 dead $wzr = SUBSWri renamable $w1, 4, 0, implicit-def $nzcv
195 Bcc 9, %bb.2, implicit killed $nzcv
198 renamable $w0 = MOVi32imm 1
202 successors: %bb.3, %bb.4
205 renamable $w9 = MOVi32imm 67305985
206 renamable $w8 = ORRWrs $wzr, renamable $w1, 0, implicit-def $x8
207 STRWui killed renamable $w9, %stack.0.tmp, 0 :: (volatile store 4 into %ir.tmp41)
208 renamable $x9 = ADDXri %stack.0.tmp, 0, 0
209 renamable $w10 = LDRBBroX renamable $x9, renamable $x8, 0, 0 :: (volatile load 1 from %ir.tmp6)
210 dead $wzr = SUBSWri killed renamable $w1, 2, 0, implicit-def $nzcv
211 STRWui killed renamable $w10, renamable $x0, 0 :: (store 4 into %ir.tmp92)
212 Bcc 8, %bb.4, implicit killed $nzcv
216 liveins: $x0, $x8, $x9
218 renamable $w8 = LDRBBroX killed renamable $x9, killed renamable $x8, 0, 0 :: (volatile load 1 from %ir.sunkaddr)
219 STRWui killed renamable $w8, killed renamable $x0, 1 :: (store 4 into %ir.tmp14)
222 renamable $w0 = COPY $wzr
227 RET_ReallyLR implicit $w0