Compiler projects using llvm
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -passes=instcombine %s | FileCheck %s

declare void @add_byval_callee(double*)

declare void @add_byval_callee_2(double* byval(double))

define void @add_byval(i64* %in) {
; CHECK-LABEL: @add_byval(
; CHECK-NEXT:    call void bitcast (void (double*)* @add_byval_callee to void (i64*)*)(i64* byval(i64) [[IN:%.*]])
; CHECK-NEXT:    ret void
;
  %tmp = bitcast void (double*)* @add_byval_callee to void (i64*)*
  call void %tmp(i64* byval(i64) %in)
  ret void
}

define void @add_byval_2(i64* %in) {
; CHECK-LABEL: @add_byval_2(
; CHECK-NEXT:    [[TMP1:%.*]] = bitcast i64* [[IN:%.*]] to double*
; CHECK-NEXT:    call void @add_byval_callee_2(double* byval(double) [[TMP1]])
; CHECK-NEXT:    ret void
;
  %tmp = bitcast void (double*)* @add_byval_callee_2 to void (i64*)*
  call void %tmp(i64* byval(i64) %in)
  ret void
}

%t2 = type { i8 }

define void @vararg_byval(i8* %p) {
; CHECK-LABEL: @vararg_byval(
; CHECK-NEXT:    call void (i8, ...) @vararg_callee(i8 undef, i8* byval(i8) [[P:%.*]])
; CHECK-NEXT:    ret void
;
  %tmp = bitcast i8* %p to %t2*
  call void (i8, ...) @vararg_callee(i8 undef, %t2* byval(%t2) %tmp)
  ret void
}

declare void @vararg_callee(i8, ...)