; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --include-generated-funcs
; RUN: if [ %llvmver -lt 16 ]; then %opt < %s %loadEnzyme -enzyme -enzyme-preopt=false -mem2reg -simplifycfg -adce -instsimplify -S | FileCheck %s; fi
; RUN: %opt < %s %newLoadEnzyme -passes="enzyme,function(mem2reg,%simplifycfg,adce,instsimplify)" -enzyme-preopt=false -S | FileCheck %s

%struct.Gradients = type { float, float }
%struct.ExtGradients = type { double, double }

; Function Attrs: nounwind
declare %struct.ExtGradients @__enzyme_fwddiff(double (float)*, ...)

define double @tester(float %x) {
entry:
  %y = fpext float %x to double
  ret double %y
}

define %struct.ExtGradients @test_derivative(float %x) {
entry:
  %0 = tail call %struct.ExtGradients (double (float)*, ...) @__enzyme_fwddiff(double (float)* nonnull @tester,  metadata !"enzyme_width", i64 2, float %x, float 1.0, float 2.0)
  ret %struct.ExtGradients %0
}

; CHECK: define {{[^@]+}}@fwddiffe2tester(float [[X:%.*]], [2 x float] %"x'")
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP0:%.*]] = extractvalue [2 x float] %"x'", 0
; CHECK-NEXT:    %"y'ipc" = fpext float [[TMP0]] to double
; CHECK-NEXT:    [[TMP1:%.*]] = insertvalue [2 x double] undef, double %"y'ipc", 0
; CHECK-NEXT:    [[TMP2:%.*]] = extractvalue [2 x float] %"x'", 1
; CHECK-NEXT:    %"y'ipc1" = fpext float [[TMP2]] to double
; CHECK-NEXT:    [[TMP3:%.*]] = insertvalue [2 x double] [[TMP1]], double %"y'ipc1", 1
; CHECK-NEXT:    ret [2 x double] [[TMP3]]
;
