; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseFloat16.ll (ZN4Simd4Base23SquaredDifferenceSum16fEPKtS2_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: alwaysinline mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef, i64 noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base23SquaredDifferenceSum16fEPKtS2_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 i64, align 8
  %10 = alloca [4 x float], align 16
  %11 = alloca i64, align 8
  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 8, ptr %9) #5
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = call noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef %12, i64 noundef 4)
  store i64 %13, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #5
  call void @llvm.memset.p0.i64(ptr align 16 %10, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %75, %4
  %15 = load i64, ptr %11, align 8, !tbaa !9
  %16 = load i64, ptr %9, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %18, label %78

18:                                               ; preds = %14
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i64, ptr %11, align 8, !tbaa !9
  %21 = add i64 %20, 0
  %22 = getelementptr inbounds i16, ptr %19, i64 %21
  %23 = load i16, ptr %22, align 2, !tbaa !11
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = add i64 %25, 0
  %27 = getelementptr inbounds i16, ptr %24, i64 %26
  %28 = load i16, ptr %27, align 2, !tbaa !11
  %29 = call noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext %23, i16 noundef zeroext %28)
  %30 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 0
  %31 = load float, ptr %30, align 16, !tbaa !13
  %32 = fadd float %31, %29
  store float %32, ptr %30, align 16, !tbaa !13
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = load i64, ptr %11, align 8, !tbaa !9
  %35 = add i64 %34, 1
  %36 = getelementptr inbounds i16, ptr %33, i64 %35
  %37 = load i16, ptr %36, align 2, !tbaa !11
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = load i64, ptr %11, align 8, !tbaa !9
  %40 = add i64 %39, 1
  %41 = getelementptr inbounds i16, ptr %38, i64 %40
  %42 = load i16, ptr %41, align 2, !tbaa !11
  %43 = call noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext %37, i16 noundef zeroext %42)
  %44 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 1
  %45 = load float, ptr %44, align 4, !tbaa !13
  %46 = fadd float %45, %43
  store float %46, ptr %44, align 4, !tbaa !13
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load i64, ptr %11, align 8, !tbaa !9
  %49 = add i64 %48, 2
  %50 = getelementptr inbounds i16, ptr %47, i64 %49
  %51 = load i16, ptr %50, align 2, !tbaa !11
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load i64, ptr %11, align 8, !tbaa !9
  %54 = add i64 %53, 2
  %55 = getelementptr inbounds i16, ptr %52, i64 %54
  %56 = load i16, ptr %55, align 2, !tbaa !11
  %57 = call noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext %51, i16 noundef zeroext %56)
  %58 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 2
  %59 = load float, ptr %58, align 8, !tbaa !13
  %60 = fadd float %59, %57
  store float %60, ptr %58, align 8, !tbaa !13
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = load i64, ptr %11, align 8, !tbaa !9
  %63 = add i64 %62, 3
  %64 = getelementptr inbounds i16, ptr %61, i64 %63
  %65 = load i16, ptr %64, align 2, !tbaa !11
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load i64, ptr %11, align 8, !tbaa !9
  %68 = add i64 %67, 3
  %69 = getelementptr inbounds i16, ptr %66, i64 %68
  %70 = load i16, ptr %69, align 2, !tbaa !11
  %71 = call noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext %65, i16 noundef zeroext %70)
  %72 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 3
  %73 = load float, ptr %72, align 4, !tbaa !13
  %74 = fadd float %73, %71
  store float %74, ptr %72, align 4, !tbaa !13
  br label %75

75:                                               ; preds = %18
  %76 = load i64, ptr %11, align 8, !tbaa !9
  %77 = add i64 %76, 4
  store i64 %77, ptr %11, align 8, !tbaa !9
  br label %14, !llvm.loop !15

78:                                               ; preds = %14
  br label %79

79:                                               ; preds = %96, %78
  %80 = load i64, ptr %11, align 8, !tbaa !9
  %81 = load i64, ptr %7, align 8, !tbaa !9
  %82 = icmp ult i64 %80, %81
  br i1 %82, label %83, label %99

83:                                               ; preds = %79
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = load i64, ptr %11, align 8, !tbaa !9
  %86 = getelementptr inbounds i16, ptr %84, i64 %85
  %87 = load i16, ptr %86, align 2, !tbaa !11
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = load i64, ptr %11, align 8, !tbaa !9
  %90 = getelementptr inbounds i16, ptr %88, i64 %89
  %91 = load i16, ptr %90, align 2, !tbaa !11
  %92 = call noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext %87, i16 noundef zeroext %91)
  %93 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 0
  %94 = load float, ptr %93, align 16, !tbaa !13
  %95 = fadd float %94, %92
  store float %95, ptr %93, align 16, !tbaa !13
  br label %96

96:                                               ; preds = %83
  %97 = load i64, ptr %11, align 8, !tbaa !9
  %98 = add i64 %97, 1
  store i64 %98, ptr %11, align 8, !tbaa !9
  br label %79, !llvm.loop !17

99:                                               ; preds = %79
  %100 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 0
  %101 = load float, ptr %100, align 16, !tbaa !13
  %102 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 1
  %103 = load float, ptr %102, align 4, !tbaa !13
  %104 = fadd float %101, %103
  %105 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 2
  %106 = load float, ptr %105, align 8, !tbaa !13
  %107 = fadd float %104, %106
  %108 = getelementptr inbounds [4 x float], ptr %10, i64 0, i64 3
  %109 = load float, ptr %108, align 4, !tbaa !13
  %110 = fadd float %107, %109
  %111 = load ptr, ptr %8, align 8, !tbaa !5
  store float %110, ptr %111, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext, i16 noundef zeroext) #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 nounwind willreturn memory(argmem: write) }
attributes #4 = { alwaysinline 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 #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 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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 i64 @_ZN4Simd7AlignLoEmm(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN4Simd4Base23SquaredDifferenceSum16fEPKtS2_mPf(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i64 noundef %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  %5 = tail call noundef i64 @_ZN4Simd7AlignLoEmm(i64 noundef %2, i64 noundef 4)
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %4
  %.sroa.0.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %12, %.lr.ph ]
  %.sroa.8.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %19, %.lr.ph ]
  %.sroa.11.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %26, %.lr.ph ]
  %.sroa.14.0.lcssa = phi float [ 0.000000e+00, %4 ], [ %33, %.lr.ph ]
  %.0.lcssa = phi i64 [ 0, %4 ], [ %34, %.lr.ph ]
  %6 = icmp ult i64 %.0.lcssa, %2
  br i1 %6, label %.lr.ph43, label %._crit_edge

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.036 = phi i64 [ %34, %.lr.ph ], [ 0, %4 ]
  %.sroa.14.035 = phi float [ %33, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.sroa.11.034 = phi float [ %26, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.sroa.8.033 = phi float [ %19, %.lr.ph ], [ 0.000000e+00, %4 ]
  %.sroa.0.032 = phi float [ %12, %.lr.ph ], [ 0.000000e+00, %4 ]
  %7 = getelementptr inbounds i16, ptr %0, i64 %.036
  %8 = load i16, ptr %7, align 2, !tbaa !5
  %9 = getelementptr inbounds i16, ptr %1, i64 %.036
  %10 = load i16, ptr %9, align 2, !tbaa !5
  %11 = tail call noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext %8, i16 noundef zeroext %10)
  %12 = fadd float %.sroa.0.032, %11
  %13 = or disjoint i64 %.036, 1
  %14 = getelementptr inbounds i16, ptr %0, i64 %13
  %15 = load i16, ptr %14, align 2, !tbaa !5
  %16 = getelementptr inbounds i16, ptr %1, i64 %13
  %17 = load i16, ptr %16, align 2, !tbaa !5
  %18 = tail call noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext %15, i16 noundef zeroext %17)
  %19 = fadd float %.sroa.8.033, %18
  %20 = or disjoint i64 %.036, 2
  %21 = getelementptr inbounds i16, ptr %0, i64 %20
  %22 = load i16, ptr %21, align 2, !tbaa !5
  %23 = getelementptr inbounds i16, ptr %1, i64 %20
  %24 = load i16, ptr %23, align 2, !tbaa !5
  %25 = tail call noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext %22, i16 noundef zeroext %24)
  %26 = fadd float %.sroa.11.034, %25
  %27 = or disjoint i64 %.036, 3
  %28 = getelementptr inbounds i16, ptr %0, i64 %27
  %29 = load i16, ptr %28, align 2, !tbaa !5
  %30 = getelementptr inbounds i16, ptr %1, i64 %27
  %31 = load i16, ptr %30, align 2, !tbaa !5
  %32 = tail call noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext %29, i16 noundef zeroext %31)
  %33 = fadd float %.sroa.14.035, %32
  %34 = add i64 %.036, 4
  %35 = icmp ult i64 %34, %5
  br i1 %35, label %.lr.ph, label %.preheader, !llvm.loop !9

.lr.ph43:                                         ; preds = %.preheader, %.lr.ph43
  %.142 = phi i64 [ %42, %.lr.ph43 ], [ %.0.lcssa, %.preheader ]
  %.sroa.0.141 = phi float [ %41, %.lr.ph43 ], [ %.sroa.0.0.lcssa, %.preheader ]
  %36 = getelementptr inbounds i16, ptr %0, i64 %.142
  %37 = load i16, ptr %36, align 2, !tbaa !5
  %38 = getelementptr inbounds i16, ptr %1, i64 %.142
  %39 = load i16, ptr %38, align 2, !tbaa !5
  %40 = tail call noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext %37, i16 noundef zeroext %39)
  %41 = fadd float %.sroa.0.141, %40
  %42 = add i64 %.142, 1
  %exitcond.not = icmp eq i64 %42, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph43, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph43, %.preheader
  %.sroa.0.1.lcssa = phi float [ %.sroa.0.0.lcssa, %.preheader ], [ %41, %.lr.ph43 ]
  %43 = fadd float %.sroa.8.0.lcssa, %.sroa.0.1.lcssa
  %44 = fadd float %.sroa.11.0.lcssa, %43
  %45 = fadd float %.sroa.14.0.lcssa, %44
  store float %45, ptr %3, align 4, !tbaa !12
  ret void
}

; Function Attrs: alwaysinline mustprogress uwtable
declare dso_local noundef float @_ZN4Simd4Base20SquaredDifference16fEtt(i16 noundef zeroext, i16 noundef zeroext) local_unnamed_addr #2

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 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 = { alwaysinline 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" }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"float", !7, i64 0}


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