; LLVM IR from huawei-noah/bolt :: compute/tensor/src/cpu/general (convolution)

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

%struct.TensorDesc = type { i32, i32, i32, [20 x i32] }
%struct.ConvolutionParamSpec = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %union.ActivationSpec, i32, i32, i32, i32 }
%union.ActivationSpec = type { %struct.ClipParamSpec }
%struct.ClipParamSpec = type { float, float }
%struct.ActivationParamSpec = type { i32, [4 x float] }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z19convolution_general10TensorDescPvS0_S_PKv20ConvolutionParamSpecS_S2_S_S2_jS0_S_S0_19ActivationParamSpec(ptr noundef byval(%struct.TensorDesc) align 8 %0, ptr noundef %1, ptr noundef %2, ptr noundef byval(%struct.TensorDesc) align 8 %3, ptr noundef %4, ptr noundef byval(%struct.ConvolutionParamSpec) align 8 %5, ptr noundef byval(%struct.TensorDesc) align 8 %6, ptr noundef %7, ptr noundef byval(%struct.TensorDesc) align 8 %8, ptr noundef %9, i32 noundef %10, ptr noundef %11, ptr noundef byval(%struct.TensorDesc) align 8 %12, ptr noundef %13, ptr noundef byval(%struct.ActivationParamSpec) align 8 %14) #0 {
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i32, align 4
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  %24 = alloca %struct.TensorDesc, align 8
  %25 = alloca %struct.TensorDesc, align 8
  %26 = alloca i32, align 4
  store ptr %1, ptr %16, align 8, !tbaa !5
  store ptr %2, ptr %17, align 8, !tbaa !5
  store ptr %4, ptr %18, align 8, !tbaa !5
  store ptr %7, ptr %19, align 8, !tbaa !5
  store ptr %9, ptr %20, align 8, !tbaa !5
  store i32 %10, ptr %21, align 4, !tbaa !9
  store ptr %11, ptr %22, align 8, !tbaa !5
  store ptr %13, ptr %23, align 8, !tbaa !5
  %27 = load ptr, ptr %17, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %33

29:                                               ; preds = %15
  %30 = load ptr, ptr %23, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %24, ptr align 8 %12, i64 92, i1 false), !tbaa.struct !11
  %31 = call noundef i32 @_Z14tensorNumBytes10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8 %24)
  %32 = zext i32 %31 to i64
  call void @_Z10UNI_MEMSETPvim(ptr noundef %30, i32 noundef 0, i64 noundef %32)
  br label %38

33:                                               ; preds = %15
  %34 = load ptr, ptr %23, align 8, !tbaa !5
  %35 = load ptr, ptr %17, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %25, ptr align 8 %12, i64 92, i1 false), !tbaa.struct !11
  %36 = call noundef i32 @_Z14tensorNumBytes10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8 %25)
  %37 = zext i32 %36 to i64
  call void @_Z10UNI_MEMCPYPvPKvm(ptr noundef %34, ptr noundef %35, i64 noundef %37)
  br label %38

38:                                               ; preds = %33, %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #5
  store i32 51, ptr %26, align 4, !tbaa !17
  %39 = getelementptr inbounds %struct.TensorDesc, ptr %3, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !19
  switch i32 %40, label %41 [
  ]

41:                                               ; preds = %38
  store i32 51, ptr %26, align 4, !tbaa !17
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %26, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #5
  ret i32 %43
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z10UNI_MEMSETPvim(ptr noundef, i32 noundef, i64 noundef) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z14tensorNumBytes10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z10UNI_MEMCPYPvPKvm(ptr noundef, ptr noundef, i64 noundef) #2

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

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

attributes #0 = { 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 #1 = { inlinehint 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 = { inlinehint 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: readwrite) }
attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !14, i64 8, i64 4, !9, i64 12, i64 80, !16}
!12 = !{!13, !13, i64 0}
!13 = !{!"_ZTS8DataType", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"_ZTS10DataFormat", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"_ZTS2EE", !7, i64 0}
!19 = !{!20, !13, i64 0}
!20 = !{!"_ZTS10TensorDesc", !13, i64 0, !15, i64 4, !10, i64 8, !7, i64 12}


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

%struct.TensorDesc = type { i32, i32, i32, [20 x i32] }
%struct.ConvolutionParamSpec = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %union.ActivationSpec, i32, i32, i32, i32 }
%union.ActivationSpec = type { %struct.ClipParamSpec }
%struct.ClipParamSpec = type { float, float }
%struct.ActivationParamSpec = type { i32, [4 x float] }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z19convolution_general10TensorDescPvS0_S_PKv20ConvolutionParamSpecS_S2_S_S2_jS0_S_S0_19ActivationParamSpec(ptr nocapture noundef readnone byval(%struct.TensorDesc) align 8 %0, ptr nocapture noundef readnone %1, ptr noundef %2, ptr nocapture noundef readnone byval(%struct.TensorDesc) align 8 %3, ptr nocapture noundef readnone %4, ptr nocapture noundef readnone byval(%struct.ConvolutionParamSpec) align 8 %5, ptr nocapture noundef readnone byval(%struct.TensorDesc) align 8 %6, ptr nocapture noundef readnone %7, ptr nocapture noundef readnone byval(%struct.TensorDesc) align 8 %8, ptr nocapture noundef readnone %9, i32 noundef %10, ptr nocapture noundef readnone %11, ptr nocapture noundef readonly byval(%struct.TensorDesc) align 8 %12, ptr noundef %13, ptr nocapture noundef readnone byval(%struct.ActivationParamSpec) align 8 %14) local_unnamed_addr #0 {
  %16 = icmp eq ptr %2, null
  %17 = tail call noundef i32 @_Z14tensorNumBytes10TensorDesc(ptr noundef nonnull byval(%struct.TensorDesc) align 8 %12)
  %18 = zext i32 %17 to i64
  br i1 %16, label %19, label %20

19:                                               ; preds = %15
  tail call void @_Z10UNI_MEMSETPvim(ptr noundef %13, i32 noundef 0, i64 noundef %18)
  br label %21

20:                                               ; preds = %15
  tail call void @_Z10UNI_MEMCPYPvPKvm(ptr noundef %13, ptr noundef nonnull %2, i64 noundef %18)
  br label %21

21:                                               ; preds = %20, %19
  ret i32 51
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z10UNI_MEMSETPvim(ptr noundef, i32 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z14tensorNumBytes10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z10UNI_MEMCPYPvPKvm(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { inlinehint 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 = { inlinehint 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)"}


; Effective O3 passes: DSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass