; LLVM IR from aferikoglou/GenHLSOptimizer :: dataset/spcl_example_01/Example1_Pipelined.ll (Z15Simple1DStencilPKfPf)

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

17:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store i32 1, ptr %7, align 4, !tbaa !11
  br label %18

18:                                               ; preds = %42, %17
  %19 = load i32, ptr %7, align 4, !tbaa !11
  %20 = icmp slt i32 %19, 1023999
  br i1 %20, label %22, label %21

21:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %45

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !11
  %25 = add nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds float, ptr %23, i64 %26
  %28 = load float, ptr %27, align 4, !tbaa !9
  store float %28, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store float 0x3FD554C980000000, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %29 = load float, ptr %5, align 4, !tbaa !9
  %30 = load float, ptr %6, align 4, !tbaa !9
  %31 = fadd float %29, %30
  %32 = load float, ptr %8, align 4, !tbaa !9
  %33 = fadd float %31, %32
  %34 = fmul float 0x3FD554C980000000, %33
  store float %34, ptr %10, align 4, !tbaa !9
  %35 = load float, ptr %6, align 4, !tbaa !9
  store float %35, ptr %5, align 4, !tbaa !9
  %36 = load float, ptr %8, align 4, !tbaa !9
  store float %36, ptr %6, align 4, !tbaa !9
  %37 = load float, ptr %10, align 4, !tbaa !9
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i32, ptr %7, align 4, !tbaa !11
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds float, ptr %38, i64 %40
  store float %37, ptr %41, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %42

42:                                               ; preds = %22
  %43 = load i32, ptr %7, align 4, !tbaa !11
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %7, align 4, !tbaa !11
  br label %18, !llvm.loop !13

45:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

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

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !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 @_Z15Simple1DStencilPKfPf(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
vector.memcheck:
  %2 = load <2 x float>, ptr %0, align 4, !tbaa !5
  %3 = ptrtoint ptr %1 to i64
  %4 = ptrtoint ptr %0 to i64
  %5 = add i64 %3, -4
  %6 = sub i64 %5, %4
  %diff.check = icmp ult i64 %6, 32
  br i1 %diff.check, label %scalar.ph.preheader.new, label %vector.ph

scalar.ph.preheader.new:                          ; preds = %middle.block, %vector.memcheck
  %indvars.iv.ph = phi i64 [ 1, %vector.memcheck ], [ 1023993, %middle.block ]
  %.ph = phi <2 x float> [ %2, %vector.memcheck ], [ %25, %middle.block ]
  br label %scalar.ph

vector.ph:                                        ; preds = %vector.memcheck
  %7 = shufflevector <2 x float> %2, <2 x float> poison, <4 x i32> <i32 poison, i32 poison, i32 poison, i32 0>
  %8 = shufflevector <2 x float> %2, <2 x float> poison, <4 x i32> <i32 poison, i32 poison, i32 poison, i32 1>
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vector.recur = phi <4 x float> [ %7, %vector.ph ], [ %13, %vector.body ]
  %vector.recur20 = phi <4 x float> [ %8, %vector.ph ], [ %wide.load21, %vector.body ]
  %offset.idx = or disjoint i64 %index, 1
  %9 = or disjoint i64 %index, 2
  %10 = getelementptr inbounds float, ptr %0, i64 %9
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  %wide.load = load <4 x float>, ptr %10, align 4, !tbaa !5
  %wide.load21 = load <4 x float>, ptr %11, align 4, !tbaa !5
  %12 = shufflevector <4 x float> %vector.recur20, <4 x float> %wide.load, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %13 = shufflevector <4 x float> %wide.load, <4 x float> %wide.load21, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %14 = shufflevector <4 x float> %vector.recur, <4 x float> %12, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %15 = shufflevector <4 x float> %12, <4 x float> %13, <4 x i32> <i32 3, i32 4, i32 5, i32 6>
  %16 = fadd <4 x float> %12, %14
  %17 = fadd <4 x float> %13, %15
  %18 = fadd <4 x float> %16, %wide.load
  %19 = fadd <4 x float> %17, %wide.load21
  %20 = fmul <4 x float> %18, <float 0x3FD554C980000000, float 0x3FD554C980000000, float 0x3FD554C980000000, float 0x3FD554C980000000>
  %21 = fmul <4 x float> %19, <float 0x3FD554C980000000, float 0x3FD554C980000000, float 0x3FD554C980000000, float 0x3FD554C980000000>
  %22 = getelementptr inbounds float, ptr %1, i64 %offset.idx
  %23 = getelementptr inbounds i8, ptr %22, i64 16
  store <4 x float> %20, ptr %22, align 4, !tbaa !5
  store <4 x float> %21, ptr %23, align 4, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %24 = icmp eq i64 %index.next, 1023992
  br i1 %24, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %25 = shufflevector <4 x float> %wide.load21, <4 x float> poison, <2 x i32> <i32 2, i32 3>
  br label %scalar.ph.preheader.new

.loopexit:                                        ; preds = %scalar.ph
  ret void

scalar.ph:                                        ; preds = %scalar.ph, %scalar.ph.preheader.new
  %indvars.iv = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader.new ], [ %indvars.iv.next.1, %scalar.ph ]
  %26 = phi <2 x float> [ %.ph, %scalar.ph.preheader.new ], [ %42, %scalar.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next
  %28 = load float, ptr %27, align 4, !tbaa !5
  %shift = shufflevector <2 x float> %26, <2 x float> poison, <2 x i32> <i32 1, i32 poison>
  %29 = fadd <2 x float> %shift, %26
  %30 = extractelement <2 x float> %29, i64 0
  %31 = fadd float %30, %28
  %32 = fmul float %31, 0x3FD554C980000000
  %33 = getelementptr inbounds float, ptr %1, i64 %indvars.iv
  store float %32, ptr %33, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %34 = getelementptr inbounds float, ptr %0, i64 %indvars.iv.next.1
  %35 = load float, ptr %34, align 4, !tbaa !5
  %36 = extractelement <2 x float> %26, i64 1
  %37 = fadd float %28, %36
  %38 = fadd float %37, %35
  %39 = fmul float %38, 0x3FD554C980000000
  %40 = getelementptr inbounds float, ptr %1, i64 %indvars.iv.next
  store float %39, ptr %40, align 4, !tbaa !5
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 1023999
  %41 = insertelement <2 x float> poison, float %28, i64 0
  %42 = insertelement <2 x float> %41, float %35, i64 1
  br i1 %exitcond.not.1, label %.loopexit, label %scalar.ph, !llvm.loop !13
}

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 = 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: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,VectorCombinePass