brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.1 KiB · d5b1319 Raw
95 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 x86_64-linux %s -o - | FileCheck %s --check-prefix=CHECK17 18define dso_local void @f(i32 %n, ptr nocapture %x) {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: pushq %rbp81; CHECK: movq %rsp, %rbp82 83; Saving the SP via llvm.stacksave()84; CHECK: movq %rsp, [[SAVE:%r[a-z0-9]+]]85; VLA allocation86; CHECK: movq %rsp, [[TMP:%r[a-z0-9]+]]87; CHECK: subq %r{{[a-z0-9]+}}, [[TMP]]88; CHECK: movq [[TMP]], %rsp89 90; The next instruction comes from llvm.stackrestore()91; CHECK:      movq [[SAVE]], %rsp92; Epilogue93; CHECK-NEXT: movq %rbp, %rsp94; CHECK-NEXT: popq %rbp95