; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseNeural.ll (ZN4Simd4Base30NeuralConvolutionForwardGemmNNEmmmPKfS2_Pf)

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN4Simd4Base30NeuralConvolutionForwardGemmNNEmmmPKfS2_Pf(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #1 {
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca float, align 4
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca i64, align 8
  store i64 %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  store ptr %5, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store i64 0, ptr %13, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %74, %6
  %21 = load i64, ptr %13, align 8, !tbaa !5
  %22 = load i64, ptr %7, align 8, !tbaa !5
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  store i32 2, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  br label %77

25:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  store i64 0, ptr %15, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %70, %25
  %27 = load i64, ptr %15, align 8, !tbaa !5
  %28 = load i64, ptr %9, align 8, !tbaa !5
  %29 = icmp ult i64 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  store i32 5, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %73

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %32 = load ptr, ptr %10, align 8, !tbaa !9
  %33 = load i64, ptr %13, align 8, !tbaa !5
  %34 = load i64, ptr %9, align 8, !tbaa !5
  %35 = mul i64 %33, %34
  %36 = load i64, ptr %15, align 8, !tbaa !5
  %37 = add i64 %35, %36
  %38 = getelementptr inbounds float, ptr %32, i64 %37
  %39 = load float, ptr %38, align 4, !tbaa !11
  store float %39, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %40 = load ptr, ptr %11, align 8, !tbaa !9
  %41 = load i64, ptr %15, align 8, !tbaa !5
  %42 = load i64, ptr %8, align 8, !tbaa !5
  %43 = mul i64 %41, %42
  %44 = getelementptr inbounds float, ptr %40, i64 %43
  store ptr %44, ptr %17, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #3
  %45 = load ptr, ptr %12, align 8, !tbaa !9
  %46 = load i64, ptr %13, align 8, !tbaa !5
  %47 = load i64, ptr %8, align 8, !tbaa !5
  %48 = mul i64 %46, %47
  %49 = getelementptr inbounds float, ptr %45, i64 %48
  store ptr %49, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  store i64 0, ptr %19, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %66, %31
  %51 = load i64, ptr %19, align 8, !tbaa !5
  %52 = load i64, ptr %8, align 8, !tbaa !5
  %53 = icmp ult i64 %51, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %50
  store i32 8, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  br label %69

55:                                               ; preds = %50
  %56 = load float, ptr %16, align 4, !tbaa !11
  %57 = load ptr, ptr %17, align 8, !tbaa !9
  %58 = load i64, ptr %19, align 8, !tbaa !5
  %59 = getelementptr inbounds float, ptr %57, i64 %58
  %60 = load float, ptr %59, align 4, !tbaa !11
  %61 = load ptr, ptr %18, align 8, !tbaa !9
  %62 = load i64, ptr %19, align 8, !tbaa !5
  %63 = getelementptr inbounds float, ptr %61, i64 %62
  %64 = load float, ptr %63, align 4, !tbaa !11
  %65 = call float @llvm.fmuladd.f32(float %56, float %60, float %64)
  store float %65, ptr %63, align 4, !tbaa !11
  br label %66

66:                                               ; preds = %55
  %67 = load i64, ptr %19, align 8, !tbaa !5
  %68 = add i64 %67, 1
  store i64 %68, ptr %19, align 8, !tbaa !5
  br label %50, !llvm.loop !13

69:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %70

70:                                               ; preds = %69
  %71 = load i64, ptr %15, align 8, !tbaa !5
  %72 = add i64 %71, 1
  store i64 %72, ptr %15, align 8, !tbaa !5
  br label %26, !llvm.loop !15

73:                                               ; preds = %30
  br label %74

74:                                               ; preds = %73
  %75 = load i64, ptr %13, align 8, !tbaa !5
  %76 = add i64 %75, 1
  store i64 %76, ptr %13, align 8, !tbaa !5
  br label %20, !llvm.loop !16

77:                                               ; preds = %24
  ret void
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN4Simd4Base30NeuralConvolutionForwardGemmNNEmmmPKfS2_Pf(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef readonly %4, ptr nocapture noundef %5) local_unnamed_addr #0 {
  %.not = icmp eq i64 %0, 0
  %.not34 = icmp eq i64 %2, 0
  %or.cond = or i1 %.not, %.not34
  %.not35 = icmp eq i64 %1, 0
  %or.cond40 = or i1 %or.cond, %.not35
  br i1 %or.cond40, label %._crit_edge, label %.preheader.us.us.preheader

.preheader.us.us.preheader:                       ; preds = %6
  %7 = shl i64 %1, 2
  %8 = mul i64 %2, %1
  %9 = shl i64 %8, 2
  %scevgep42 = getelementptr i8, ptr %4, i64 %9
  %10 = getelementptr i8, ptr %5, i64 %7
  %min.iters.check = icmp ult i64 %1, 8
  %stride.check = icmp slt i64 %7, 0
  %n.vec = and i64 %1, -8
  %cmp.n = icmp eq i64 %n.vec, %1
  %xtraiter = and i64 %1, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  %11 = add i64 %1, -1
  br label %.preheader.us.us

.preheader.us.us:                                 ; preds = %.preheader.us.us.preheader, %._crit_edge29.split.us.us.us
  %.02330.us.us = phi i64 [ %49, %._crit_edge29.split.us.us.us ], [ 0, %.preheader.us.us.preheader ]
  %12 = mul i64 %7, %.02330.us.us
  %scevgep = getelementptr i8, ptr %5, i64 %12
  %scevgep41 = getelementptr i8, ptr %10, i64 %12
  %13 = mul i64 %.02330.us.us, %2
  %14 = getelementptr float, ptr %3, i64 %13
  %15 = mul i64 %.02330.us.us, %1
  %16 = getelementptr inbounds float, ptr %5, i64 %15
  %bound0 = icmp ult ptr %scevgep, %scevgep42
  %bound1 = icmp ugt ptr %scevgep41, %4
  %found.conflict = and i1 %bound0, %bound1
  %17 = or i1 %found.conflict, %stride.check
  br label %.lr.ph.us.us.us

.lr.ph.us.us.us:                                  ; preds = %._crit_edge.us.us.us, %.preheader.us.us
  %.02427.us.us.us = phi i64 [ 0, %.preheader.us.us ], [ %48, %._crit_edge.us.us.us ]
  %18 = getelementptr float, ptr %14, i64 %.02427.us.us.us
  %19 = load float, ptr %18, align 4, !tbaa !5
  %20 = mul i64 %.02427.us.us.us, %1
  %21 = getelementptr inbounds float, ptr %4, i64 %20
  %brmerge = or i1 %min.iters.check, %17
  br i1 %brmerge, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.us.us.us
  %broadcast.splatinsert = insertelement <4 x float> poison, float %19, i64 0
  %broadcast.splat = shufflevector <4 x float> %broadcast.splatinsert, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %22 = getelementptr inbounds float, ptr %21, i64 %index
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  %wide.load = load <4 x float>, ptr %22, align 4, !tbaa !5, !alias.scope !9
  %wide.load43 = load <4 x float>, ptr %23, align 4, !tbaa !5, !alias.scope !9
  %24 = getelementptr inbounds float, ptr %16, i64 %index
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %wide.load44 = load <4 x float>, ptr %24, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %wide.load45 = load <4 x float>, ptr %25, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %26 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat, <4 x float> %wide.load, <4 x float> %wide.load44)
  %27 = tail call <4 x float> @llvm.fmuladd.v4f32(<4 x float> %broadcast.splat, <4 x float> %wide.load43, <4 x float> %wide.load45)
  store <4 x float> %26, ptr %24, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  store <4 x float> %27, ptr %25, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 8
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge.us.us.us, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph.us.us.us, %middle.block
  %.026.us.us.us.ph = phi i64 [ 0, %.lr.ph.us.us.us ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader
  %29 = getelementptr inbounds float, ptr %21, i64 %.026.us.us.us.ph
  %30 = load float, ptr %29, align 4, !tbaa !5
  %31 = getelementptr inbounds float, ptr %16, i64 %.026.us.us.us.ph
  %32 = load float, ptr %31, align 4, !tbaa !5
  %33 = tail call float @llvm.fmuladd.f32(float %19, float %30, float %32)
  store float %33, ptr %31, align 4, !tbaa !5
  %34 = or disjoint i64 %.026.us.us.us.ph, 1
  br label %scalar.ph.prol.loopexit

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %.026.us.us.us.unr = phi i64 [ %.026.us.us.us.ph, %scalar.ph.preheader ], [ %34, %scalar.ph.prol ]
  %35 = icmp eq i64 %.026.us.us.us.ph, %11
  br i1 %35, label %._crit_edge.us.us.us, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %.026.us.us.us = phi i64 [ %47, %scalar.ph ], [ %.026.us.us.us.unr, %scalar.ph.prol.loopexit ]
  %36 = getelementptr inbounds float, ptr %21, i64 %.026.us.us.us
  %37 = load float, ptr %36, align 4, !tbaa !5
  %38 = getelementptr inbounds float, ptr %16, i64 %.026.us.us.us
  %39 = load float, ptr %38, align 4, !tbaa !5
  %40 = tail call float @llvm.fmuladd.f32(float %19, float %37, float %39)
  store float %40, ptr %38, align 4, !tbaa !5
  %41 = add nuw i64 %.026.us.us.us, 1
  %42 = getelementptr inbounds float, ptr %21, i64 %41
  %43 = load float, ptr %42, align 4, !tbaa !5
  %44 = getelementptr inbounds float, ptr %16, i64 %41
  %45 = load float, ptr %44, align 4, !tbaa !5
  %46 = tail call float @llvm.fmuladd.f32(float %19, float %43, float %45)
  store float %46, ptr %44, align 4, !tbaa !5
  %47 = add nuw i64 %.026.us.us.us, 2
  %exitcond.not.1 = icmp eq i64 %47, %1
  br i1 %exitcond.not.1, label %._crit_edge.us.us.us, label %scalar.ph, !llvm.loop !18

._crit_edge.us.us.us:                             ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %48 = add nuw i64 %.02427.us.us.us, 1
  %exitcond38.not = icmp eq i64 %48, %2
  br i1 %exitcond38.not, label %._crit_edge29.split.us.us.us, label %.lr.ph.us.us.us, !llvm.loop !19

._crit_edge29.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %49 = add nuw i64 %.02330.us.us, 1
  %exitcond39.not = icmp eq i64 %49, %0
  br i1 %exitcond39.not, label %._crit_edge, label %.preheader.us.us, !llvm.loop !20

._crit_edge:                                      ; preds = %._crit_edge29.split.us.us.us, %6
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x float> @llvm.fmuladd.v4f32(<4 x float>, <4 x float>, <4 x float>) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) 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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = distinct !{!10, !11}
!11 = distinct !{!11, !"LVerDomain"}
!12 = !{!13}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !15, !16, !17}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!"llvm.loop.isvectorized", i32 1}
!17 = !{!"llvm.loop.unroll.runtime.disable"}
!18 = distinct !{!18, !15, !16}
!19 = distinct !{!19, !15}
!20 = distinct !{!20, !15}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass