; 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z25getSymmetricQuantizeScalejjPKfPf(i32 noundef, i32 noundef, ptr noundef, ptr 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 @_Z15quantizeF32ToI810TensorDescPKfPS_PaPfi(ptr noundef byval(%struct.TensorDesc) align 8 %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i32 noundef %5) #3 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca %struct.TensorDesc, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca float, align 4
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store i32 %5, ptr %12, align 4, !tbaa !9
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  %19 = icmp eq ptr %18, null
  br i1 %19, label %20, label %21

20:                                               ; preds = %6
  store i32 2, ptr %7, align 4
  br label %65

21:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 8 %0, i64 92, i1 false), !tbaa.struct !11
  %22 = call noundef i32 @_Z17tensorNumElements10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8 %14)
  store i32 %22, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %23 = load i32, ptr %13, align 4, !tbaa !9
  %24 = udiv i32 %23, 16
  store i32 %24, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %25 = load i32, ptr %13, align 4, !tbaa !9
  %26 = urem i32 %25, 16
  %27 = 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 %26)
  %28 = fsub double %27, 1.000000e+00
  %29 = fptoui double %28 to i32
  store i32 %29, ptr %16, align 4, !tbaa !9
  %30 = load i32, ptr %12, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %36

32:                                               ; preds = %21
  %33 = load ptr, ptr %11, align 8, !tbaa !5
  %34 = load float, ptr %33, align 4, !tbaa !17
  %35 = fcmp ole float %34, 0.000000e+00
  br i1 %35, label %36, label %55

36:                                               ; preds = %32, %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %37 = load ptr, ptr %11, align 8, !tbaa !5
  %38 = load float, ptr %37, align 4, !tbaa !17
  store float %38, ptr %17, align 4, !tbaa !17
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = load i32, ptr %16, align 4, !tbaa !9
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %11, align 8, !tbaa !5
  call void @_Z25getSymmetricQuantizeScalejjPKfPf(i32 noundef %39, i32 noundef %40, ptr noundef %41, ptr noundef %42)
  %43 = load float, ptr %17, align 4, !tbaa !17
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = load float, ptr %44, align 4, !tbaa !17
  %46 = fcmp ogt float %43, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %36
  %48 = load float, ptr %17, align 4, !tbaa !17
  br label %52

49:                                               ; preds = %36
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = load float, ptr %50, align 4, !tbaa !17
  br label %52

52:                                               ; preds = %49, %47
  %53 = phi float [ %48, %47 ], [ %51, %49 ]
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  store float %53, ptr %54, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  br label %55

55:                                               ; preds = %52, %32
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = load ptr, ptr %10, align 8, !tbaa !5
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  %59 = load i32, ptr %15, align 4, !tbaa !9
  %60 = load i32, ptr %16, align 4, !tbaa !9
  %61 = call { ptr, ptr, ptr } asm sideeffect "vbroadcastss ($2), %zmm0             \0A\09mov $$127, %ebx \0A\09vmovd %ebx, %xmm1                    \0A\09vbroadcastss %xmm1, %zmm4            \0A\09mov $$-127, %ebx \0A\09vmovd %ebx, %xmm1                    \0A\09vbroadcastss %xmm1, %zmm5            \0A\09mov $3, %ebx \0A\09cmp $$0x0, %ebx                         \0A\09je 1f                                    \0A\09.align 16                             \0A\090:                                    \0A\09vmulps ($0), %zmm0, %zmm1            \0A\09vcvtps2dq %zmm1, %zmm2              \0A\09vpmaxsd %zmm5, %zmm2, %zmm3          \0A\09vpminsd %zmm4, %zmm3, %zmm1          \0A\09vpmovsdb %zmm1, ($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\09vmulps ($0), %zmm0, %zmm1 {%k1}      \0A\09vcvtps2dq %zmm1, %zmm2              \0A\09vpmaxsd %zmm5, %zmm2, %zmm3          \0A\09vpminsd %zmm4, %zmm3, %zmm1          \0A\09vpmovsdb %zmm1, ($1) {%k1}        \0A\09.align 16                             \0A\092:                                    \0A\09", "=r,=r,=r,r,{ax},0,1,2,~{k1},~{ebx},~{zmm0},~{zmm1},~{zmm2},~{zmm3},~{zmm4},~{zmm5},~{memory},~{cc},~{dirflag},~{fpsr},~{flags}"(i32 %59, i32 %60, ptr %56, ptr %57, ptr %58) #4, !srcloc !19
  %62 = extractvalue { ptr, ptr, ptr } %61, 0
  %63 = extractvalue { ptr, ptr, ptr } %61, 1
  %64 = extractvalue { ptr, ptr, ptr } %61, 2
  store ptr %62, ptr %8, align 8, !tbaa !5
  store ptr %63, ptr %10, align 8, !tbaa !5
  store ptr %64, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %65

65:                                               ; preds = %55, %20
  %66 = load i32, ptr %7, align 4
  ret i32 %66
}

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 = { 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 = !{!"float", !7, i64 0}
!19 = !{i64 10211, i64 10252, i64 10284, i64 10339, i64 10394, i64 10427, i64 10482, i64 10537, i64 10567, i64 10623, i64 10680, i64 10734, i64 10788, i64 10843, i64 10897, i64 10953, i64 11009, i64 11063, i64 11117, i64 11171, i64 11225, i64 11279, i64 11335, i64 11389, i64 11443, i64 11497, i64 11551, i64 11609, i64 11663, i64 11719, i64 11775, i64 11829, i64 11883, i64 11937}


; 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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z17tensorNumElements10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8) local_unnamed_addr #0

; 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 #0

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

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 3) i32 @_Z15quantizeF32ToI810TensorDescPKfPS_PaPfi(ptr nocapture noundef readonly byval(%struct.TensorDesc) align 8 %0, ptr noundef %1, ptr nocapture noundef readnone %2, ptr noundef %3, ptr noundef %4, i32 noundef %5) local_unnamed_addr #1 {
  %7 = icmp eq ptr %4, null
  br i1 %7, label %21, label %8

8:                                                ; preds = %6
  %9 = tail call noundef i32 @_Z17tensorNumElements10TensorDesc(ptr noundef nonnull byval(%struct.TensorDesc) align 8 %0)
  %10 = lshr i32 %9, 4
  %11 = and i32 %9, 15
  %12 = 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 %11)
  %13 = fadd double %12, -1.000000e+00
  %14 = fptoui double %13 to i32
  %.not = icmp ne i32 %5, 0
  %.pre = load float, ptr %4, align 4, !tbaa !5
  %15 = fcmp ugt float %.pre, 0.000000e+00
  %or.cond = select i1 %.not, i1 %15, i1 false
  br i1 %or.cond, label %19, label %16

16:                                               ; preds = %8
  tail call void @_Z25getSymmetricQuantizeScalejjPKfPf(i32 noundef %10, i32 noundef %14, ptr noundef %1, ptr noundef nonnull %4)
  %17 = load float, ptr %4, align 4, !tbaa !5
  %18 = fcmp ogt float %.pre, %17
  %. = select i1 %18, float %.pre, float %17
  store float %., ptr %4, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %8, %16
  %20 = tail call { ptr, ptr, ptr } asm sideeffect "vbroadcastss ($2), %zmm0             \0A\09mov $$127, %ebx \0A\09vmovd %ebx, %xmm1                    \0A\09vbroadcastss %xmm1, %zmm4            \0A\09mov $$-127, %ebx \0A\09vmovd %ebx, %xmm1                    \0A\09vbroadcastss %xmm1, %zmm5            \0A\09mov $3, %ebx \0A\09cmp $$0x0, %ebx                         \0A\09je 1f                                    \0A\09.align 16                             \0A\090:                                    \0A\09vmulps ($0), %zmm0, %zmm1            \0A\09vcvtps2dq %zmm1, %zmm2              \0A\09vpmaxsd %zmm5, %zmm2, %zmm3          \0A\09vpminsd %zmm4, %zmm3, %zmm1          \0A\09vpmovsdb %zmm1, ($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\09vmulps ($0), %zmm0, %zmm1 {%k1}      \0A\09vcvtps2dq %zmm1, %zmm2              \0A\09vpmaxsd %zmm5, %zmm2, %zmm3          \0A\09vpminsd %zmm4, %zmm3, %zmm1          \0A\09vpmovsdb %zmm1, ($1) {%k1}        \0A\09.align 16                             \0A\092:                                    \0A\09", "=r,=r,=r,r,{ax},0,1,2,~{k1},~{ebx},~{zmm0},~{zmm1},~{zmm2},~{zmm3},~{zmm4},~{zmm5},~{memory},~{cc},~{dirflag},~{fpsr},~{flags}"(i32 %10, i32 %14, ptr %1, ptr %3, ptr nonnull %4) #2, !srcloc !9
  br label %21

21:                                               ; preds = %6, %19
  %.0 = phi i32 [ 0, %19 ], [ 2, %6 ]
  ret i32 %.0
}

attributes #0 = { 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 #1 = { 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 #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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 10211, i64 10252, i64 10284, i64 10339, i64 10394, i64 10427, i64 10482, i64 10537, i64 10567, i64 10623, i64 10680, i64 10734, i64 10788, i64 10843, i64 10897, i64 10953, i64 11009, i64 11063, i64 11117, i64 11171, i64 11225, i64 11279, i64 11335, i64 11389, i64 11443, i64 11497, i64 11551, i64 11609, i64 11663, i64 11719, i64 11775, i64 11829, i64 11883, i64 11937}


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