; LLVM IR from ermig1979/Simd :: src/Simd/SimdBaseNeural.ll (ZN4Simd4Base20NeuralDerivativeReluEPKfmS2_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 @_ZN4Simd4Base20NeuralDerivativeReluEPKfmS2_Pf(ptr noundef %0, i64 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca float, align 4
  %10 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %11 = load ptr, ptr %7, align 8, !tbaa !5
  %12 = getelementptr inbounds float, ptr %11, i64 0
  %13 = load float, ptr %12, align 4, !tbaa !11
  store float %13, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  store i64 0, ptr %10, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %35, %4
  %15 = load i64, ptr %10, align 8, !tbaa !9
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %38

19:                                               ; preds = %14
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %10, align 8, !tbaa !9
  %22 = getelementptr inbounds float, ptr %20, i64 %21
  %23 = load float, ptr %22, align 4, !tbaa !11
  %24 = fcmp ogt float %23, 0.000000e+00
  br i1 %24, label %25, label %26

25:                                               ; preds = %19
  br label %28

26:                                               ; preds = %19
  %27 = load float, ptr %9, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %26, %25
  %29 = phi float [ 1.000000e+00, %25 ], [ %27, %26 ]
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load i64, ptr %10, align 8, !tbaa !9
  %32 = getelementptr inbounds float, ptr %30, i64 %31
  %33 = load float, ptr %32, align 4, !tbaa !11
  %34 = fmul float %33, %29
  store float %34, ptr %32, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %28
  %36 = load i64, ptr %10, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr %10, align 8, !tbaa !9
  br label %14, !llvm.loop !13

38:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

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 = { 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 = distinct !{!13, !14}
!14 = !{!"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: mustprogress nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @_ZN4Simd4Base20NeuralDerivativeReluEPKfmS2_Pf(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef %3) local_unnamed_addr #0 {
  %5 = load float, ptr %2, align 4, !tbaa !5
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %min.iters.check = icmp ult i64 %1, 8
  br i1 %min.iters.check, label %.lr.ph.preheader13, label %vector.memcheck

.lr.ph.preheader13:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %.08.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %1, 1
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader13
  %6 = getelementptr inbounds float, ptr %0, i64 %.08.ph
  %7 = load float, ptr %6, align 4, !tbaa !5
  %8 = fcmp ogt float %7, 0.000000e+00
  %9 = select i1 %8, float 1.000000e+00, float %5
  %10 = getelementptr inbounds float, ptr %3, i64 %.08.ph
  %11 = load float, ptr %10, align 4, !tbaa !5
  %12 = fmul float %11, %9
  store float %12, ptr %10, align 4, !tbaa !5
  %13 = or disjoint i64 %.08.ph, 1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader13
  %.08.unr = phi i64 [ %.08.ph, %.lr.ph.preheader13 ], [ %13, %.lr.ph.prol ]
  %14 = add i64 %1, -1
  %15 = icmp eq i64 %.08.ph, %14
  br i1 %15, label %._crit_edge, label %.lr.ph

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %16 = shl i64 %1, 2
  %scevgep = getelementptr i8, ptr %3, i64 %16
  %scevgep9 = getelementptr i8, ptr %0, i64 %16
  %bound0 = icmp ugt ptr %scevgep9, %3
  %bound1 = icmp ugt ptr %scevgep, %0
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.preheader13, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %1, -8
  %broadcast.splatinsert = insertelement <4 x float> poison, float %5, 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 ]
  %17 = getelementptr inbounds float, ptr %0, i64 %index
  %18 = getelementptr inbounds i8, ptr %17, i64 16
  %wide.load = load <4 x float>, ptr %17, align 4, !tbaa !5, !alias.scope !9
  %wide.load10 = load <4 x float>, ptr %18, align 4, !tbaa !5, !alias.scope !9
  %19 = fcmp ogt <4 x float> %wide.load, zeroinitializer
  %20 = fcmp ogt <4 x float> %wide.load10, zeroinitializer
  %21 = select <4 x i1> %19, <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, <4 x float> %broadcast.splat
  %22 = select <4 x i1> %20, <4 x float> <float 1.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, <4 x float> %broadcast.splat
  %23 = getelementptr inbounds float, ptr %3, i64 %index
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  %wide.load11 = load <4 x float>, ptr %23, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %wide.load12 = load <4 x float>, ptr %24, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %25 = fmul <4 x float> %wide.load11, %21
  %26 = fmul <4 x float> %wide.load12, %22
  store <4 x float> %25, ptr %23, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  store <4 x float> %26, ptr %24, align 4, !tbaa !5, !alias.scope !12, !noalias !9
  %index.next = add nuw i64 %index, 8
  %27 = icmp eq i64 %index.next, %n.vec
  br i1 %27, label %middle.block, label %vector.body, !llvm.loop !14

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %1
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader13

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %4
  ret void

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.08 = phi i64 [ %43, %.lr.ph ], [ %.08.unr, %.lr.ph.prol.loopexit ]
  %28 = getelementptr inbounds float, ptr %0, i64 %.08
  %29 = load float, ptr %28, align 4, !tbaa !5
  %30 = fcmp ogt float %29, 0.000000e+00
  %31 = select i1 %30, float 1.000000e+00, float %5
  %32 = getelementptr inbounds float, ptr %3, i64 %.08
  %33 = load float, ptr %32, align 4, !tbaa !5
  %34 = fmul float %33, %31
  store float %34, ptr %32, align 4, !tbaa !5
  %35 = add nuw i64 %.08, 1
  %36 = getelementptr inbounds float, ptr %0, i64 %35
  %37 = load float, ptr %36, align 4, !tbaa !5
  %38 = fcmp ogt float %37, 0.000000e+00
  %39 = select i1 %38, float 1.000000e+00, float %5
  %40 = getelementptr inbounds float, ptr %3, i64 %35
  %41 = load float, ptr %40, align 4, !tbaa !5
  %42 = fmul float %41, %39
  store float %42, ptr %40, align 4, !tbaa !5
  %43 = add nuw i64 %.08, 2
  %exitcond.not.1 = icmp eq i64 %43, %1
  br i1 %exitcond.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !18
}

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" }

!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}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass