Compiler projects using llvm
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -verify-machineinstrs -csky-no-aliases < %s -mtriple=csky  | FileCheck %s

@p_fun = global void (i32, i32)* @bar, align 8

declare void @bar(i32, i32)

define void @foo(i32 %a, i32* %ptr){
; CHECK-LABEL: foo:
; CHECK:       # %bb.0: # %entry
; CHECK-NEXT:    subi16 sp, sp, 4
; CHECK-NEXT:    .cfi_def_cfa_offset 4
; CHECK-NEXT:    st32.w lr, (sp, 0) # 4-byte Folded Spill
; CHECK-NEXT:    .cfi_offset lr, -4
; CHECK-NEXT:    subi16 sp, sp, 4
; CHECK-NEXT:    .cfi_def_cfa_offset 8
; CHECK-NEXT:    ld16.w a1, (a1, 0)
; CHECK-NEXT:    lrw32 a2, [.LCPI0_0]
; CHECK-NEXT:    jsr16 a2
; CHECK-NEXT:    addi16 sp, sp, 4
; CHECK-NEXT:    ld32.w lr, (sp, 0) # 4-byte Folded Reload
; CHECK-NEXT:    addi16 sp, sp, 4
; CHECK-NEXT:    rts16
; CHECK-NEXT:    .p2align 1
; CHECK-NEXT:  # %bb.1:
; CHECK-NEXT:    .p2align 2
; CHECK-NEXT:  .LCPI0_0:
; CHECK-NEXT:    .long bar
;
entry:
  %0 = load i32, i32* %ptr
  tail call void (i32, i32) @bar(i32 %a, i32 %0)
  ret void
}

define void @foo_indirect(i32 %a, i32* %ptr) {
; CHECK-LABEL: foo_indirect:
; CHECK:       # %bb.0: # %entry
; CHECK-NEXT:    subi16 sp, sp, 4
; CHECK-NEXT:    .cfi_def_cfa_offset 4
; CHECK-NEXT:    st32.w lr, (sp, 0) # 4-byte Folded Spill
; CHECK-NEXT:    .cfi_offset lr, -4
; CHECK-NEXT:    subi16 sp, sp, 4
; CHECK-NEXT:    .cfi_def_cfa_offset 8
; CHECK-NEXT:    lrw32 a2, [.LCPI1_0]
; CHECK-NEXT:    ld16.w a2, (a2, 0)
; CHECK-NEXT:    ld16.w a1, (a1, 0)
; CHECK-NEXT:    jsr16 a2
; CHECK-NEXT:    addi16 sp, sp, 4
; CHECK-NEXT:    ld32.w lr, (sp, 0) # 4-byte Folded Reload
; CHECK-NEXT:    addi16 sp, sp, 4
; CHECK-NEXT:    rts16
; CHECK-NEXT:    .p2align 1
; CHECK-NEXT:  # %bb.1:
; CHECK-NEXT:    .p2align 2
; CHECK-NEXT:  .LCPI1_0:
; CHECK-NEXT:    .long p_fun
;
entry:
  %0 = load void (i32, i32)*, void (i32, i32)** @p_fun, align 8
  %1 = load i32, i32* %ptr
  tail call void (i32, i32) %0(i32 %a, i32 %1)
  ret void
}