157 lines · plain
1; RUN: llc < %s -mtriple=i686-pc-win32 | FileCheck %s2; RUN: llc < %s -mtriple=i686-pc-win32 -O03 4%struct.S = type { [1024 x i8] }5%struct.T = type { [3000 x i8] }6%struct.U = type { [10000 x i8] }7 8define void @basics() {9; CHECK-LABEL: basics:10entry:11 br label %bb112 13; Allocation move sizes should have been removed.14; CHECK-NOT: movl $102415; CHECK-NOT: movl $300016 17bb1:18 %p0 = alloca %struct.S19; The allocation is small enough not to require stack probing, but the %esp20; offset after the prologue is not known, so the stack must be touched before21; the pointer is adjusted.22; CHECK: pushl %eax23; CHECK: subl $1020, %esp24 25 %saved_stack = tail call ptr @llvm.stacksave()26 27 %p1 = alloca %struct.S28; We know the %esp offset from above, so there is no need to touch the stack29; before adjusting it.30; CHECK: subl $1024, %esp31 32 %p2 = alloca %struct.T33; The offset is now 2048 bytes, so allocating a T must touch the stack again.34; CHECK: pushl %eax35; CHECK: subl $2996, %esp36 37 call void @f(ptr %p0)38; CHECK: calll39 40 %p3 = alloca %struct.T41; The call above touched the stack, so there is room for a T object.42; CHECK: subl $3000, %esp43 44 %p4 = alloca %struct.U45; The U object is large enough to require stack probing.46; CHECK: movl $10000, %eax47; CHECK: calll __chkstk48 49 %p5 = alloca %struct.T50; The stack probing above touched the tip of the stack, so there's room for a T.51; CHECK: subl $3000, %esp52 53 call void @llvm.stackrestore(ptr %saved_stack)54 %p6 = alloca %struct.S55; The stack restore means we lose track of the stack pointer and must probe.56; CHECK: pushl %eax57; CHECK: subl $1020, %esp58 59; Use the pointers so they're not optimized away.60 call void @f(ptr %p1)61 call void @g(ptr %p2)62 call void @g(ptr %p3)63 call void @h(ptr %p4)64 call void @g(ptr %p5)65 ret void66}67 68define void @loop() {69; CHECK-LABEL: loop:70entry:71 br label %bb172 73bb1:74 %p1 = alloca %struct.S75; The entry offset is unknown; touch-and-sub.76; CHECK: pushl %eax77; CHECK: subl $1020, %esp78 br label %loop179 80loop1:81 %i1 = phi i32 [ 10, %bb1 ], [ %dec1, %loop1 ]82 %p2 = alloca %struct.S83; We know the incoming offset from bb1, but from the back-edge, we assume the84; worst, and therefore touch-and-sub to allocate.85; CHECK: pushl %eax86; CHECK: subl $1020, %esp87 %dec1 = sub i32 %i1, 188 %cmp1 = icmp sgt i32 %i1, 089 br i1 %cmp1, label %loop1, label %end90; CHECK: decl91; CHECK: jg92 93end:94 call void @f(ptr %p1)95 call void @f(ptr %p2)96 ret void97}98 99define void @probe_size_attribute() "stack-probe-size"="512" {100; CHECK-LABEL: probe_size_attribute:101entry:102 br label %bb1103 104bb1:105 %p0 = alloca %struct.S106; The allocation would be small enough not to require probing, if it wasn't107; for the stack-probe-size attribute.108; CHECK: movl $1024, %eax109; CHECK: calll __chkstk110 call void @f(ptr %p0)111 ret void112}113 114define void @cfg(i1 %x, i1 %y) {115; Test that the blocks are analyzed in the correct order.116; CHECK-LABEL: cfg:117entry:118 br i1 %x, label %bb1, label %bb3119 120bb1:121 %p1 = alloca %struct.S122; CHECK: pushl %eax123; CHECK: subl $1020, %esp124 br label %bb4125 126bb2:127 %p5 = alloca %struct.T128; CHECK: pushl %eax129; CHECK: subl $2996, %esp130 call void @g(ptr %p5)131 ret void132 133bb3:134 %p2 = alloca %struct.T135; CHECK: pushl %eax136; CHECK: subl $2996, %esp137 br label %bb4138 139bb4:140 br i1 %y, label %bb5, label %bb2141 142bb5:143 %p4 = alloca %struct.S144; CHECK: subl $1024, %esp145 call void @f(ptr %p4)146 ret void147 148}149 150 151declare void @f(ptr)152declare void @g(ptr)153declare void @h(ptr)154 155declare ptr @llvm.stacksave()156declare void @llvm.stackrestore(ptr)157