; LLVM IR from zchrissirhcz/pixel :: legacy/cnnlayer (relu_layer)

; 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: nounwind uwtable
define dso_local void @relu_f32_forward_asimd(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %9 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %9, ptr %8, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %30, %3
  %11 = load i32, ptr %8, align 4, !tbaa !9
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = icmp ult i32 %11, %12
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = load float, ptr %16, align 4, !tbaa !11
  %18 = fcmp ogt float %17, 0.000000e+00
  br i1 %18, label %19, label %22

19:                                               ; preds = %15
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load float, ptr %20, align 4, !tbaa !11
  br label %23

22:                                               ; preds = %15
  br label %23

23:                                               ; preds = %22, %19
  %24 = phi float [ %21, %19 ], [ 0.000000e+00, %22 ]
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  store float %24, ptr %25, align 4, !tbaa !11
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds float, ptr %26, i32 1
  store ptr %27, ptr %5, align 8, !tbaa !5
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds float, ptr %28, i32 1
  store ptr %29, ptr %4, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %23
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = add i32 %31, 1
  store i32 %32, ptr %8, align 4, !tbaa !9
  br label %10, !llvm.loop !13

33:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @relu_f32_forward_asimd(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %3
  %4 = ptrtoint ptr %1 to i64
  %5 = ptrtoint ptr %0 to i64
  %6 = zext i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 8
  %7 = sub i64 %4, %5
  %diff.check = icmp ult i64 %7, 32
  %or.cond = or i1 %min.iters.check, %diff.check
  br i1 %or.cond, label %.lr.ph.preheader23, label %vector.ph

.lr.ph.preheader23:                               ; preds = %middle.block, %.lr.ph.preheader
  %.013.ph = phi i32 [ 0, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.0812.ph = phi ptr [ %0, %.lr.ph.preheader ], [ %ind.end14, %middle.block ]
  %.0911.ph = phi ptr [ %1, %.lr.ph.preheader ], [ %ind.end16, %middle.block ]
  %8 = sub i32 %2, %.013.ph
  %xtraiter = and i32 %8, 1
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader23
  %9 = load float, ptr %.0812.ph, align 4, !tbaa !5
  %10 = fcmp ogt float %9, 0.000000e+00
  %11 = select i1 %10, float %9, float 0.000000e+00
  store float %11, ptr %.0911.ph, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %.0911.ph, i64 4
  %13 = getelementptr inbounds i8, ptr %.0812.ph, i64 4
  %14 = add nuw i32 %.013.ph, 1
  br label %.lr.ph.prol.loopexit

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader23
  %.013.unr = phi i32 [ %.013.ph, %.lr.ph.preheader23 ], [ %14, %.lr.ph.prol ]
  %.0812.unr = phi ptr [ %.0812.ph, %.lr.ph.preheader23 ], [ %13, %.lr.ph.prol ]
  %.0911.unr = phi ptr [ %.0911.ph, %.lr.ph.preheader23 ], [ %12, %.lr.ph.prol ]
  %15 = add i32 %2, -1
  %16 = icmp eq i32 %.013.ph, %15
  br i1 %16, label %._crit_edge, label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %6, 4294967288
  %ind.end = trunc nuw i64 %n.vec to i32
  %17 = shl nuw nsw i64 %n.vec, 2
  %ind.end14 = getelementptr i8, ptr %0, i64 %17
  %18 = shl nuw nsw i64 %n.vec, 2
  %ind.end16 = getelementptr i8, ptr %1, i64 %18
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = shl i64 %index, 2
  %next.gep = getelementptr i8, ptr %0, i64 %offset.idx
  %offset.idx19 = shl i64 %index, 2
  %next.gep20 = getelementptr i8, ptr %1, i64 %offset.idx19
  %19 = getelementptr i8, ptr %next.gep, i64 16
  %wide.load = load <4 x float>, ptr %next.gep, align 4, !tbaa !5
  %wide.load22 = load <4 x float>, ptr %19, align 4, !tbaa !5
  %20 = fcmp ogt <4 x float> %wide.load, zeroinitializer
  %21 = fcmp ogt <4 x float> %wide.load22, zeroinitializer
  %22 = select <4 x i1> %20, <4 x float> %wide.load, <4 x float> zeroinitializer
  %23 = select <4 x i1> %21, <4 x float> %wide.load22, <4 x float> zeroinitializer
  %24 = getelementptr i8, ptr %next.gep20, i64 16
  store <4 x float> %22, ptr %next.gep20, align 4, !tbaa !5
  store <4 x float> %23, ptr %24, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !9

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

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

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %.013 = phi i32 [ %36, %.lr.ph ], [ %.013.unr, %.lr.ph.prol.loopexit ]
  %.0812 = phi ptr [ %35, %.lr.ph ], [ %.0812.unr, %.lr.ph.prol.loopexit ]
  %.0911 = phi ptr [ %34, %.lr.ph ], [ %.0911.unr, %.lr.ph.prol.loopexit ]
  %26 = load float, ptr %.0812, align 4, !tbaa !5
  %27 = fcmp ogt float %26, 0.000000e+00
  %28 = select i1 %27, float %26, float 0.000000e+00
  store float %28, ptr %.0911, align 4, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %.0911, i64 4
  %30 = getelementptr inbounds i8, ptr %.0812, i64 4
  %31 = load float, ptr %30, align 4, !tbaa !5
  %32 = fcmp ogt float %31, 0.000000e+00
  %33 = select i1 %32, float %31, float 0.000000e+00
  store float %33, ptr %29, align 4, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %.0911, i64 8
  %35 = getelementptr inbounds i8, ptr %.0812, i64 8
  %36 = add nuw i32 %.013, 2
  %exitcond.not.1 = icmp eq i32 %36, %2
  br i1 %exitcond.not.1, label %._crit_edge, label %.lr.ph, !llvm.loop !13
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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/C++ TBAA"}
!9 = distinct !{!9, !10, !11, !12}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.isvectorized", i32 1}
!12 = !{!"llvm.loop.unroll.runtime.disable"}
!13 = distinct !{!13, !10, !11}


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