llvm/llvm/test/CodeGen/AArch64/wineh_shrinkwrap.mir

# RUN: llc -O2 -o - %s -mtriple=aarch64-windows -start-before=shrink-wrap \
# RUN:   -stop-after=prologepilog | FileCheck %s --check-prefix=WIN64
# RUN: llc -O2 -o - %s -mtriple=aarch64-linux -start-before=shrink-wrap \
# RUN:   -stop-after=prologepilog | FileCheck %s --check-prefix=LINUX

# This tests checks that shrink wrapping bails out on Windows AMR64 due to the
# use of Windows CFI.  We don't currently support fragments for WIndows EH on
# ARM64.
# The same test gets shrink wrapped on Linux ARM64.

# WIN64-LABEL: bb.0.entry:
# WIN64: early-clobber $sp = frame-setup STRXpre killed $x19, $sp, -32
# WIN64-LABEL: bb.1:
# WIN64-LABEL: bb.2.if.then:

# LINUX-LABEL: bb.0.entry:
# LINUX-LABEL: bb.1:
# LINUX-LABEL: bb.2.if.then:
# LINUX: early-clobber $sp = frame-setup STRXpre killed $fp, $sp, -32
--- |
  ; ModuleID = 'shrink.cpp'
  target datalayout = "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128"
  target triple = "aarch64-unknown-windows-msvc19.11.0"

  define dso_local i32 @"?func@@YAHHH@Z"(i32 %a, i32 %b) local_unnamed_addr #0 {
  entry:
    %A = alloca [1000 x i32], align 4
    %cmp = icmp sgt i32 %a, 1
    br i1 %cmp, label %if.then, label %return

  if.then:                                          ; preds = %entry
    %0 = bitcast ptr %A to ptr
    call void @llvm.lifetime.start.p0(i64 4000, ptr nonnull %0) #3
    %arraydecay2 = bitcast ptr %A to ptr
    call void @"?init@@YAXPEAH@Z"(ptr nonnull %arraydecay2)
    %arrayidx = getelementptr inbounds [1000 x i32], ptr %A, i64 0, i64 100
    %1 = load i32, ptr %arrayidx, align 4, !tbaa !2
    %add = add i32 %b, 1
    %add1 = add i32 %add, %1
    call void @llvm.lifetime.end.p0(i64 4000, ptr nonnull %0) #3
    br label %return

  return:                                           ; preds = %entry, %if.then
    %retval.0 = phi i32 [ %add1, %if.then ], [ 0, %entry ]
    ret i32 %retval.0
  }

  ; Function Attrs: argmemonly nounwind
  declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #1

  declare dso_local void @"?init@@YAXPEAH@Z"(ptr) local_unnamed_addr #2

  ; Function Attrs: argmemonly nounwind
  declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #1

  ; Function Attrs: nounwind
  declare void @llvm.stackprotector(ptr, ptr) #3

  attributes #0 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+neon" "unsafe-fp-math"="false" "use-soft-float"="false" }
  attributes #1 = { argmemonly nounwind }
  attributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+neon" "unsafe-fp-math"="false" "use-soft-float"="false" }
  attributes #3 = { nounwind }

  !llvm.module.flags = !{!0}
  !llvm.ident = !{!1}

  !0 = !{i32 1, !"wchar_size", i32 2}
  !1 = !{!"clang version 8.0.0"}
  !2 = !{!3, !3, i64 0}
  !3 = !{!"int", !4, i64 0}
  !4 = !{!"omnipotent char", !5, i64 0}
  !5 = !{!"Simple C++ TBAA"}

...
---
name:            '?func@@YAHHH@Z'
alignment:       4
exposesReturnsTwice: false
legalized:       false
regBankSelected: false
selected:        false
failedISel:      false
tracksRegLiveness: true
registers:
liveins:
  - { reg: '$w0', virtual-reg: '' }
  - { reg: '$w1', virtual-reg: '' }
frameInfo:
  isFrameAddressTaken: false
  isReturnAddressTaken: false
  hasStackMap:     false
  hasPatchPoint:   false
  stackSize:       0
  offsetAdjustment: 0
  maxAlignment:    4
  adjustsStack:    true
  hasCalls:        true
  stackProtector:  ''
  maxCallFrameSize: 0
  cvBytesOfCalleeSavedRegisters: 0
  hasOpaqueSPAdjustment: false
  hasVAStart:      false
  hasMustTailInVarArgFunc: false
  localFrameSize:  4000
  savePoint:       ''
  restorePoint:    ''
fixedStack:
stack:
  - { id: 0, name: A, type: default, offset: 0, size: 4000, alignment: 4,
      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
      local-offset: -4000, debug-info-variable: '', debug-info-expression: '',
      debug-info-location: '' }
constants:
body:             |
  bb.0.entry:
    successors: %bb.2(0x40000000), %bb.1(0x40000000)
    liveins: $w0, $w1

    dead $wzr = SUBSWri killed renamable $w0, 2, 0, implicit-def $nzcv
    Bcc 10, %bb.2, implicit killed $nzcv

  bb.1:
    successors: %bb.3(0x80000000)

    renamable $w0 = COPY $wzr
    B %bb.3

  bb.2.if.then:
    successors: %bb.3(0x80000000)
    liveins: $w1

    renamable $w19 = COPY $w1
    ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
    $x0 = ADDXri %stack.0.A, 0, 0
    BL @"?init@@YAXPEAH@Z", csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $x0, implicit-def $sp
    ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
    renamable $w8 = LDRWui %stack.0.A, 100 :: (dereferenceable load (s32) from %ir.arrayidx, !tbaa !2)
    renamable $w8 = ADDWrr killed renamable $w19, killed renamable $w8
    renamable $w0 = ADDWri killed renamable $w8, 1, 0

  bb.3.return:
    liveins: $w0

    RET_ReallyLR implicit $w0

...