; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseFloat16.ll (ZN4Simd4Base17CosineDistance16fEPKtS2_mPf)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZN4Simd4Base16Float16ToFloat32Et(i16 noundef zeroext) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base17CosineDistance16fEPKtS2_mPf(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca i64, align 8
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store float 0.000000e+00, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store float 0.000000e+00, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store float 0.000000e+00, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store i64 0, ptr %12, align 8, !tbaa !9
  br label %15

15:                                               ; preds = %43, %4
  %16 = load i64, ptr %12, align 8, !tbaa !9
  %17 = load i64, ptr %7, align 8, !tbaa !9
  %18 = icmp ult i64 %16, %17
  br i1 %18, label %20, label %19

19:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %46

20:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = load i64, ptr %12, align 8, !tbaa !9
  %23 = getelementptr inbounds i16, ptr %21, i64 %22
  %24 = load i16, ptr %23, align 2, !tbaa !13
  %25 = call noundef float @_ZN4Simd4Base16Float16ToFloat32Et(i16 noundef zeroext %24)
  store float %25, ptr %13, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i64, ptr %12, align 8, !tbaa !9
  %28 = getelementptr inbounds i16, ptr %26, i64 %27
  %29 = load i16, ptr %28, align 2, !tbaa !13
  %30 = call noundef float @_ZN4Simd4Base16Float16ToFloat32Et(i16 noundef zeroext %29)
  store float %30, ptr %14, align 4, !tbaa !11
  %31 = load float, ptr %13, align 4, !tbaa !11
  %32 = load float, ptr %13, align 4, !tbaa !11
  %33 = load float, ptr %9, align 4, !tbaa !11
  %34 = call float @llvm.fmuladd.f32(float %31, float %32, float %33)
  store float %34, ptr %9, align 4, !tbaa !11
  %35 = load float, ptr %13, align 4, !tbaa !11
  %36 = load float, ptr %14, align 4, !tbaa !11
  %37 = load float, ptr %10, align 4, !tbaa !11
  %38 = call float @llvm.fmuladd.f32(float %35, float %36, float %37)
  store float %38, ptr %10, align 4, !tbaa !11
  %39 = load float, ptr %14, align 4, !tbaa !11
  %40 = load float, ptr %14, align 4, !tbaa !11
  %41 = load float, ptr %11, align 4, !tbaa !11
  %42 = call float @llvm.fmuladd.f32(float %39, float %40, float %41)
  store float %42, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %43

43:                                               ; preds = %20
  %44 = load i64, ptr %12, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %12, align 8, !tbaa !9
  br label %15, !llvm.loop !15

46:                                               ; preds = %19
  %47 = load float, ptr %10, align 4, !tbaa !11
  %48 = load float, ptr %9, align 4, !tbaa !11
  %49 = load float, ptr %11, align 4, !tbaa !11
  %50 = fmul float %48, %49
  %51 = call noundef float @_ZSt4sqrtf(float noundef %50)
  %52 = fdiv float %47, %51
  %53 = fsub float 1.000000e+00, %52
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  store float %53, ptr %54, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef float @_ZN4Simd4Base16Float16ToFloat32Et(i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base17CosineDistance16fEPKtS2_mPf(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %.not = icmp eq i64 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %5 = fmul float %18, %16
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %4
  %.019.lcssa = phi float [ 0.000000e+00, %4 ], [ %17, %._crit_edge.loopexit ]
  %6 = phi float [ 0.000000e+00, %4 ], [ %5, %._crit_edge.loopexit ]
  %7 = tail call noundef float @_ZSt4sqrtf(float noundef %6)
  %8 = fdiv float %.019.lcssa, %7
  %9 = fsub float 1.000000e+00, %8
  store float %9, ptr %3, align 4, !tbaa !5
  ret void

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.025 = phi float [ %16, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.01924 = phi float [ %17, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.02023 = phi i64 [ %19, %.lr.ph ], [ 0, %4 ]
  %.02122 = phi float [ %18, %.lr.ph ], [ 0.000000e+00, %4 ]
  %10 = getelementptr inbounds i16, ptr %0, i64 %.02023
  %11 = load i16, ptr %10, align 2, !tbaa !9
  %12 = tail call noundef float @_ZN4Simd4Base16Float16ToFloat32Et(i16 noundef zeroext %11)
  %13 = getelementptr inbounds i16, ptr %1, i64 %.02023
  %14 = load i16, ptr %13, align 2, !tbaa !9
  %15 = tail call noundef float @_ZN4Simd4Base16Float16ToFloat32Et(i16 noundef zeroext %14)
  %16 = tail call float @llvm.fmuladd.f32(float %12, float %12, float %.025)
  %17 = tail call float @llvm.fmuladd.f32(float %12, float %15, float %.01924)
  %18 = tail call float @llvm.fmuladd.f32(float %15, float %15, float %.02122)
  %19 = add nuw i64 %.02023, 1
  %exitcond.not = icmp eq i64 %19, %2
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph, !llvm.loop !11
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef float @_ZSt4sqrtf(float noundef) local_unnamed_addr #3

attributes #0 = { alwaysinline mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass