; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc -mtriple=s390x-linux-gnu < %s | FileCheck -check-prefix=LINUX %s

; FIXME: Merge with llvm.sincos.ll when zos is fixed for half.

define { half, half } @test_sincos_f16(half %a) #0 {
; LINUX-LABEL: test_sincos_f16:
; LINUX:       # %bb.0:
; LINUX-NEXT:    stmg %r14, %r15, 112(%r15)
; LINUX-NEXT:    .cfi_offset %r14, -48
; LINUX-NEXT:    .cfi_offset %r15, -40
; LINUX-NEXT:    aghi %r15, -176
; LINUX-NEXT:    .cfi_def_cfa_offset 336
; LINUX-NEXT:    std %f8, 168(%r15) # 8-byte Spill
; LINUX-NEXT:    .cfi_offset %f8, -168
; LINUX-NEXT:    brasl %r14, __extendhfsf2@PLT
; LINUX-NEXT:    la %r2, 164(%r15)
; LINUX-NEXT:    la %r3, 160(%r15)
; LINUX-NEXT:    brasl %r14, sincosf@PLT
; LINUX-NEXT:    le %f0, 164(%r15)
; LINUX-NEXT:    brasl %r14, __truncsfhf2@PLT
; LINUX-NEXT:    le %f1, 160(%r15)
; LINUX-NEXT:    ler %f8, %f0
; LINUX-NEXT:    ler %f0, %f1
; LINUX-NEXT:    brasl %r14, __truncsfhf2@PLT
; LINUX-NEXT:    ler %f2, %f0
; LINUX-NEXT:    ler %f0, %f8
; LINUX-NEXT:    ld %f8, 168(%r15) # 8-byte Reload
; LINUX-NEXT:    lmg %r14, %r15, 288(%r15)
; LINUX-NEXT:    br %r14
  %result = call { half, half } @llvm.sincos.f16(half %a)
  ret { half, half } %result
}

define half @test_sincos_f16_only_use_sin(half %a) #0 {
; LINUX-LABEL: test_sincos_f16_only_use_sin:
; LINUX:       # %bb.0:
; LINUX-NEXT:    stmg %r14, %r15, 112(%r15)
; LINUX-NEXT:    .cfi_offset %r14, -48
; LINUX-NEXT:    .cfi_offset %r15, -40
; LINUX-NEXT:    aghi %r15, -168
; LINUX-NEXT:    .cfi_def_cfa_offset 328
; LINUX-NEXT:    brasl %r14, __extendhfsf2@PLT
; LINUX-NEXT:    la %r2, 160(%r15)
; LINUX-NEXT:    la %r3, 164(%r15)
; LINUX-NEXT:    brasl %r14, sincosf@PLT
; LINUX-NEXT:    le %f0, 160(%r15)
; LINUX-NEXT:    brasl %r14, __truncsfhf2@PLT
; LINUX-NEXT:    lmg %r14, %r15, 280(%r15)
; LINUX-NEXT:    br %r14
  %result = call { half, half } @llvm.sincos.f16(half %a)
  %result.0 = extractvalue { half, half } %result, 0
  ret half %result.0
}

define half @test_sincos_f16_only_use_cos(half %a) #0 {
; LINUX-LABEL: test_sincos_f16_only_use_cos:
; LINUX:       # %bb.0:
; LINUX-NEXT:    stmg %r14, %r15, 112(%r15)
; LINUX-NEXT:    .cfi_offset %r14, -48
; LINUX-NEXT:    .cfi_offset %r15, -40
; LINUX-NEXT:    aghi %r15, -168
; LINUX-NEXT:    .cfi_def_cfa_offset 328
; LINUX-NEXT:    brasl %r14, __extendhfsf2@PLT
; LINUX-NEXT:    la %r2, 164(%r15)
; LINUX-NEXT:    la %r3, 160(%r15)
; LINUX-NEXT:    brasl %r14, sincosf@PLT
; LINUX-NEXT:    le %f0, 160(%r15)
; LINUX-NEXT:    brasl %r14, __truncsfhf2@PLT
; LINUX-NEXT:    lmg %r14, %r15, 280(%r15)
; LINUX-NEXT:    br %r14
  %result = call { half, half } @llvm.sincos.f16(half %a)
  %result.1 = extractvalue { half, half } %result, 1
  ret half %result.1
}

define { <2 x half>, <2 x half> } @test_sincos_v2f16(<2 x half> %a) #0 {
; LINUX-LABEL: test_sincos_v2f16:
; LINUX:       # %bb.0:
; LINUX-NEXT:    stmg %r14, %r15, 112(%r15)
; LINUX-NEXT:    .cfi_offset %r14, -48
; LINUX-NEXT:    .cfi_offset %r15, -40
; LINUX-NEXT:    aghi %r15, -200
; LINUX-NEXT:    .cfi_def_cfa_offset 360
; LINUX-NEXT:    std %f8, 192(%r15) # 8-byte Spill
; LINUX-NEXT:    std %f9, 184(%r15) # 8-byte Spill
; LINUX-NEXT:    std %f10, 176(%r15) # 8-byte Spill
; LINUX-NEXT:    .cfi_offset %f8, -168
; LINUX-NEXT:    .cfi_offset %f9, -176
; LINUX-NEXT:    .cfi_offset %f10, -184
; LINUX-NEXT:    ler %f8, %f2
; LINUX-NEXT:    brasl %r14, __extendhfsf2@PLT
; LINUX-NEXT:    la %r2, 172(%r15)
; LINUX-NEXT:    la %r3, 168(%r15)
; LINUX-NEXT:    brasl %r14, sincosf@PLT
; LINUX-NEXT:    ler %f0, %f8
; LINUX-NEXT:    brasl %r14, __extendhfsf2@PLT
; LINUX-NEXT:    la %r2, 164(%r15)
; LINUX-NEXT:    la %r3, 160(%r15)
; LINUX-NEXT:    brasl %r14, sincosf@PLT
; LINUX-NEXT:    le %f0, 172(%r15)
; LINUX-NEXT:    brasl %r14, __truncsfhf2@PLT
; LINUX-NEXT:    le %f1, 164(%r15)
; LINUX-NEXT:    ler %f8, %f0
; LINUX-NEXT:    ler %f0, %f1
; LINUX-NEXT:    brasl %r14, __truncsfhf2@PLT
; LINUX-NEXT:    le %f1, 168(%r15)
; LINUX-NEXT:    ler %f9, %f0
; LINUX-NEXT:    ler %f0, %f1
; LINUX-NEXT:    brasl %r14, __truncsfhf2@PLT
; LINUX-NEXT:    le %f1, 160(%r15)
; LINUX-NEXT:    ler %f10, %f0
; LINUX-NEXT:    ler %f0, %f1
; LINUX-NEXT:    brasl %r14, __truncsfhf2@PLT
; LINUX-NEXT:    ler %f6, %f0
; LINUX-NEXT:    ler %f0, %f8
; LINUX-NEXT:    ler %f2, %f9
; LINUX-NEXT:    ler %f4, %f10
; LINUX-NEXT:    ld %f8, 192(%r15) # 8-byte Reload
; LINUX-NEXT:    ld %f9, 184(%r15) # 8-byte Reload
; LINUX-NEXT:    ld %f10, 176(%r15) # 8-byte Reload
; LINUX-NEXT:    lmg %r14, %r15, 312(%r15)
; LINUX-NEXT:    br %r14
  %result = call { <2 x half>, <2 x half> } @llvm.sincos.v2f16(<2 x half> %a)
  ret { <2 x half>, <2 x half> } %result
}
