brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · c21ccfe Raw
107 lines · plain
1; Test shrink wrapping placement is correct with respect to calls to llvm.{stacksave,stackrestore}2 3; void f(int n, int x[]) {4;   if (n < 0)5;     return;6;7;  int a[n];8;9;  for (int i = 0; i < n; i++)10;    a[i] = x[n - i - 1];11;12;  for (int i = 0; i < n; i++)13;    x[i] = a[i] + 1;14; }15;16; RUN: llc -mtriple aarch64-linux %s -o - | FileCheck %s17 18define dso_local void @f(i32 %n, ptr nocapture %x) uwtable {19entry:20  %cmp = icmp slt i32 %n, 021  br i1 %cmp, label %return, label %if.end22 23if.end:                                           ; preds = %entry24  %0 = zext i32 %n to i6425  %1 = tail call ptr @llvm.stacksave()26  %vla = alloca i32, i64 %0, align 1627  %cmp132 = icmp eq i32 %n, 028  br i1 %cmp132, label %for.cond.cleanup8, label %for.body.lr.ph29 30for.body.lr.ph:                                   ; preds = %if.end31  %sub = add i32 %n, -132  br label %for.body33 34for.cond6.preheader:                              ; preds = %for.body35  %cmp730 = icmp sgt i32 %n, 036  br i1 %cmp730, label %for.body9, label %for.cond.cleanup837 38for.body:                                         ; preds = %for.body, %for.body.lr.ph39  %indvars.iv34 = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next35, %for.body ]40  %2 = trunc i64 %indvars.iv34 to i3241  %sub2 = sub i32 %sub, %242  %idxprom = sext i32 %sub2 to i6443  %arrayidx = getelementptr inbounds i32, ptr %x, i64 %idxprom44  %3 = load i32, ptr %arrayidx, align 445  %arrayidx4 = getelementptr inbounds i32, ptr %vla, i64 %indvars.iv3446  store i32 %3, ptr %arrayidx4, align 447  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 148  %exitcond37 = icmp eq i64 %indvars.iv.next35, %049  br i1 %exitcond37, label %for.cond6.preheader, label %for.body50 51for.cond.cleanup8:                                ; preds = %for.body9, %if.end, %for.cond6.preheader52  tail call void @llvm.stackrestore(ptr %1)53  br label %return54 55for.body9:                                        ; preds = %for.cond6.preheader, %for.body956  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body9 ], [ 0, %for.cond6.preheader ]57  %arrayidx11 = getelementptr inbounds i32, ptr %vla, i64 %indvars.iv58  %4 = load i32, ptr %arrayidx11, align 459  %add = add nsw i32 %4, 160  %arrayidx13 = getelementptr inbounds i32, ptr %x, i64 %indvars.iv61  store i32 %add, ptr %arrayidx13, align 462  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 163  %exitcond = icmp eq i64 %indvars.iv.next, %064  br i1 %exitcond, label %for.cond.cleanup8, label %for.body965 66return:                                           ; preds = %entry, %for.cond.cleanup867  ret void68}69 70; Function Attrs: nounwind71declare ptr @llvm.stacksave()72 73; Function Attrs: nounwind74declare void @llvm.stackrestore(ptr)75 76; Check that llvm.stackrestore() happens before CSRs are popped off the stack77 78; CHECK-LABEL: f79 80; CHECK:      stp x29, x30, [sp, #-16]!81; CHECK-NEXT: .cfi_def_cfa_offset 1682; CHECK-NEXT: mov x29, sp83; CHECK-NEXT: .cfi_def_cfa w29, 1684; CHECK-NEXT: .cfi_offset w30, -885; CHECK-NEXT: .cfi_offset w29, -1686 87 88; VLA allocation89; CHECK: ubfiz	x8, x0, #2, #3290; CHECK: mov	x9, sp91; CHECK: mov	[[SAVE:x[0-9]+]], sp92; CHECK: add	x8, x8, #1593; CHECK: and	[[X1:x[0-9]+]], [[X1]], #0x7fffffff094; Saving the SP via llvm.stacksave()95; CHECK: sub	[[X1]], [[X2:x[0-9]+]], [[X1]]96 97; The next instruction comes from llvm.stackrestore()98; CHECK:      mov sp, [[SAVE]]99; Epilogue100; CHECK-NEXT: mov sp, x29101; CHECK-NEXT: .cfi_def_cfa wsp, 16102; CHECK-NEXT: ldp x29, x30, [sp], #16103; CHECK-NEXT: .cfi_def_cfa_offset 0104; CHECK-NEXT: .cfi_restore w30105; CHECK-NEXT: .cfi_restore w29106; CHECK-NEXT:  ret107