; LLVM IR from huawei-noah/bolt :: compute/tensor/src/cpu/x86/int8/avx512 (quantize)

; 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] }

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

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

; 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) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3powIijEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef, i32 noundef) #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z15quantizeI32ToI810TensorDescPKiPS_PaPf(ptr noundef byval(%struct.TensorDesc) align 8 %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #3 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca %struct.TensorDesc, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca float, align 4
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  store ptr %4, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 8 %0, i64 92, i1 false), !tbaa.struct !9
  %15 = call noundef i32 @_Z17tensorNumElements10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8 %11)
  store i32 %15, ptr %10, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %16 = load i32, ptr %10, align 4, !tbaa !14
  %17 = udiv i32 %16, 16
  store i32 %17, ptr %12, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  %18 = load i32, ptr %10, align 4, !tbaa !14
  %19 = urem i32 %18, 16
  %20 = call noundef double @_ZSt3powIijEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef 2, i32 noundef %19)
  %21 = fsub double %20, 1.000000e+00
  %22 = fptoui double %21 to i32
  store i32 %22, ptr %13, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store float 0.000000e+00, ptr %14, align 4, !tbaa !17
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load float, ptr %23, align 4, !tbaa !17
  %25 = fcmp olt float %24, 0.000000e+00
  br i1 %25, label %26, label %42

26:                                               ; preds = %5
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds float, ptr %27, i64 1
  %29 = load float, ptr %28, align 4, !tbaa !17
  %30 = fcmp ogt float %29, 0.000000e+00
  br i1 %30, label %31, label %42

31:                                               ; preds = %26
  %32 = load i32, ptr %12, align 4, !tbaa !14
  %33 = load i32, ptr %13, align 4, !tbaa !14
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_Z28getSymmetricQuantizeScaleI32jjPKiPf(i32 noundef %32, i32 noundef %33, ptr noundef %34, ptr noundef %14)
  %35 = load ptr, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds float, ptr %35, i64 1
  %37 = load float, ptr %36, align 4, !tbaa !17
  %38 = load float, ptr %14, align 4, !tbaa !17
  %39 = fmul float %37, %38
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = getelementptr inbounds float, ptr %40, i64 0
  store float %39, ptr %41, align 4, !tbaa !17
  br label %61

42:                                               ; preds = %26, %5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds float, ptr %43, i64 0
  %45 = load float, ptr %44, align 4, !tbaa !17
  %46 = fcmp ogt float %45, 0.000000e+00
  br i1 %46, label %47, label %60

47:                                               ; preds = %42
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds float, ptr %48, i64 1
  %50 = load float, ptr %49, align 4, !tbaa !17
  %51 = fcmp ogt float %50, 0.000000e+00
  br i1 %51, label %52, label %60

52:                                               ; preds = %47
  %53 = load ptr, ptr %9, align 8, !tbaa !5
  %54 = getelementptr inbounds float, ptr %53, i64 0
  %55 = load float, ptr %54, align 4, !tbaa !17
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds float, ptr %56, i64 1
  %58 = load float, ptr %57, align 4, !tbaa !17
  %59 = fdiv float %55, %58
  store float %59, ptr %14, align 4, !tbaa !17
  br label %60

60:                                               ; preds = %52, %47, %42
  br label %61

61:                                               ; preds = %60, %31
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load i32, ptr %12, align 4, !tbaa !14
  %65 = load i32, ptr %13, align 4, !tbaa !14
  %66 = call { ptr, ptr } asm sideeffect "vbroadcastss ($2), %zmm0             \0A\09mov $3, %ebx \0A\09cmp $$0x0, %ebx                         \0A\09je 1f                                    \0A\09.align 16                             \0A\090:                                    \0A\09vmovups ($0), %zmm3            \0A\09vcvtdq2ps %zmm3, %zmm2               \0A\09vmulps %zmm2, %zmm0, %zmm1            \0A\09vcvtps2dq {rn-sae}, %zmm1, %zmm2              \0A\09vpmovsdb %zmm2, ($1)                 \0A\09add $$0x40, $0                         \0A\09add $$0x10, $1                         \0A\09dec %ebx                             \0A\09jg 0b                                 \0A\09.align 16                             \0A\091:                                    \0A\09cmp $$0x0, %eax                       \0A\09je 2f                                 \0A\09kmovw %eax, %k1                     \0A\09vmovups ($0), %zmm3 {%k1}            \0A\09vcvtdq2ps %zmm3, %zmm2               \0A\09vmulps %zmm2, %zmm0, %zmm1      \0A\09vcvtps2dq {rn-sae}, %zmm1, %zmm2              \0A\09vpmovsdb %zmm2, ($1) {%k1}        \0A\09.align 16                             \0A\092:                                    \0A\09", "=r,=r,r,r,{ax},0,1,~{k1},~{ebx},~{zmm0},~{zmm1},~{zmm2},~{zmm3},~{zmm4},~{memory},~{cc},~{dirflag},~{fpsr},~{flags}"(ptr %14, i32 %64, i32 %65, ptr %62, ptr %63) #5, !srcloc !19
  %67 = extractvalue { ptr, ptr } %66, 0
  %68 = extractvalue { ptr, ptr } %66, 1
  store ptr %67, ptr %6, align 8, !tbaa !5
  store ptr %68, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z28getSymmetricQuantizeScaleI32jjPKiPf(i32 noundef, i32 noundef, ptr noundef, ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #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 = !{i64 0, i64 4, !10, i64 4, i64 4, !12, i64 8, i64 4, !14, i64 12, i64 80, !16}
!10 = !{!11, !11, i64 0}
!11 = !{!"_ZTS8DataType", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_ZTS10DataFormat", !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = !{i64 16152, i64 16193, i64 16223, i64 16279, i64 16336, i64 16390, i64 16444, i64 16492, i64 16547, i64 16604, i64 16670, i64 16724, i64 16778, i64 16832, i64 16886, i64 16940, i64 16996, i64 17050, i64 17104, i64 17158, i64 17212, i64 17269, i64 17324, i64 17375, i64 17441, i64 17495, i64 17549, i64 17603}


; 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] }

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3powIijEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z15quantizeI32ToI810TensorDescPKiPS_PaPf(ptr nocapture noundef readonly byval(%struct.TensorDesc) align 8 %0, ptr noundef %1, ptr nocapture noundef readnone %2, ptr noundef %3, ptr nocapture noundef %4) local_unnamed_addr #2 {
  %6 = alloca float, align 4
  %7 = tail call noundef i32 @_Z17tensorNumElements10TensorDesc(ptr noundef nonnull byval(%struct.TensorDesc) align 8 %0)
  %8 = lshr i32 %7, 4
  %9 = and i32 %7, 15
  %10 = tail call noundef double @_ZSt3powIijEN9__gnu_cxx9__promoteIDTplcvNS1_IT_Xsr3std12__is_integerIS2_EE7__valueEE6__typeELi0EcvNS1_IT0_Xsr3std12__is_integerIS5_EE7__valueEE6__typeELi0EEXsr3std12__is_integerIS8_EE7__valueEE6__typeES2_S5_(i32 noundef 2, i32 noundef %9)
  %11 = fadd double %10, -1.000000e+00
  %12 = fptoui double %11 to i32
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  store float 0.000000e+00, ptr %6, align 4, !tbaa !5
  %13 = load float, ptr %4, align 4, !tbaa !5
  %14 = fcmp olt float %13, 0.000000e+00
  br i1 %14, label %15, label %23

15:                                               ; preds = %5
  %16 = getelementptr inbounds i8, ptr %4, i64 4
  %17 = load float, ptr %16, align 4, !tbaa !5
  %18 = fcmp ogt float %17, 0.000000e+00
  br i1 %18, label %19, label %23

19:                                               ; preds = %15
  call void @_Z28getSymmetricQuantizeScaleI32jjPKiPf(i32 noundef %8, i32 noundef %12, ptr noundef %1, ptr noundef nonnull %6)
  %20 = load float, ptr %16, align 4, !tbaa !5
  %21 = load float, ptr %6, align 4, !tbaa !5
  %22 = fmul float %20, %21
  store float %22, ptr %4, align 4, !tbaa !5
  br label %31

23:                                               ; preds = %15, %5
  %24 = fcmp ogt float %13, 0.000000e+00
  br i1 %24, label %25, label %31

25:                                               ; preds = %23
  %26 = getelementptr inbounds i8, ptr %4, i64 4
  %27 = load float, ptr %26, align 4, !tbaa !5
  %28 = fcmp ogt float %27, 0.000000e+00
  br i1 %28, label %29, label %31

29:                                               ; preds = %25
  %30 = fdiv float %13, %27
  store float %30, ptr %6, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %23, %25, %29, %19
  %32 = call { ptr, ptr } asm sideeffect "vbroadcastss ($2), %zmm0             \0A\09mov $3, %ebx \0A\09cmp $$0x0, %ebx                         \0A\09je 1f                                    \0A\09.align 16                             \0A\090:                                    \0A\09vmovups ($0), %zmm3            \0A\09vcvtdq2ps %zmm3, %zmm2               \0A\09vmulps %zmm2, %zmm0, %zmm1            \0A\09vcvtps2dq {rn-sae}, %zmm1, %zmm2              \0A\09vpmovsdb %zmm2, ($1)                 \0A\09add $$0x40, $0                         \0A\09add $$0x10, $1                         \0A\09dec %ebx                             \0A\09jg 0b                                 \0A\09.align 16                             \0A\091:                                    \0A\09cmp $$0x0, %eax                       \0A\09je 2f                                 \0A\09kmovw %eax, %k1                     \0A\09vmovups ($0), %zmm3 {%k1}            \0A\09vcvtdq2ps %zmm3, %zmm2               \0A\09vmulps %zmm2, %zmm0, %zmm1      \0A\09vcvtps2dq {rn-sae}, %zmm1, %zmm2              \0A\09vpmovsdb %zmm2, ($1) {%k1}        \0A\09.align 16                             \0A\092:                                    \0A\09", "=r,=r,r,r,{ax},0,1,~{k1},~{ebx},~{zmm0},~{zmm1},~{zmm2},~{zmm3},~{zmm4},~{memory},~{cc},~{dirflag},~{fpsr},~{flags}"(ptr nonnull %6, i32 %8, i32 %12, ptr %1, ptr %3) #4, !srcloc !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z28getSymmetricQuantizeScaleI32jjPKiPf(i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { 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 #4 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 16152, i64 16193, i64 16223, i64 16279, i64 16336, i64 16390, i64 16444, i64 16492, i64 16547, i64 16604, i64 16670, i64 16724, i64 16778, i64 16832, i64 16886, i64 16940, i64 16996, i64 17050, i64 17104, i64 17158, i64 17212, i64 17269, i64 17324, i64 17375, i64 17441, i64 17495, i64 17549, i64 17603}


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