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

; 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 @_Z17dequantizeU8ToF3210TensorDescPhPKfS_Pf(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) #3 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.TensorDesc, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca float, align 4
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %4, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 8 %3, i64 92, i1 false), !tbaa.struct !9
  %14 = call noundef i32 @_Z17tensorNumElements10TensorDesc(ptr noundef byval(%struct.TensorDesc) align 8 %10)
  store i32 %14, ptr %9, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %15 = load i32, ptr %9, align 4, !tbaa !14
  %16 = udiv i32 %15, 16
  store i32 %16, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %17 = load i32, ptr %9, align 4, !tbaa !14
  %18 = urem i32 %17, 16
  %19 = 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 %18)
  %20 = fsub double %19, 1.000000e+00
  %21 = fptoui double %20 to i32
  store i32 %21, ptr %12, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds float, ptr %22, i64 0
  %24 = load float, ptr %23, align 4, !tbaa !17
  %25 = fdiv float 1.000000e+00, %24
  store float %25, ptr %13, align 4, !tbaa !17
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !14
  %29 = load i32, ptr %12, align 4, !tbaa !14
  %30 = call { ptr, ptr } asm sideeffect "mov $$128, %ebx \0A\09vmovd %ebx, %xmm1                    \0A\09vbroadcastss %xmm1, %zmm2            \0A\09vbroadcastss ($2), %zmm0              \0A\09mov $3, %ebx \0A\09cmp $$0x0, %ebx                         \0A\09je 1f                                    \0A\09.align 16                              \0A\090:                                     \0A\09vpmovzxbd ($1), %zmm1            \0A\09vpsubd %zmm2, %zmm1, %zmm3          \0A\09vcvtdq2ps %zmm3, %zmm4   \0A\09vmulps %zmm4, %zmm0, %zmm5          \0A\09vmovups %zmm5, ($0)                 \0A\09add $$0x40, $0                          \0A\09add $$0x10, $1                          \0A\09dec %ebx                              \0A\09jg 0b                                  \0A\09.align 16                              \0A\091:                                     \0A\09cmp $$0x0, $4                       \0A\09je 2f                                  \0A\09kmovw %eax, %k1                      \0A\09vpmovzxbd ($1), %zmm1 {%k1}      \0A\09vpsubd %zmm2, %zmm1, %zmm3          \0A\09vcvtdq2ps %zmm3, %zmm4   \0A\09vmulps %zmm4, %zmm0, %zmm5          \0A\09vmovups %zmm5, ($0) {%k1}                 \0A\09.align 16                              \0A\092:                                     \0A\09", "=r,=r,r,r,{ax},0,1,~{k1},~{ebx},~{zmm0},~{zmm1},~{zmm2},~{zmm3},~{zmm4},~{zmm5},~{memory},~{cc},~{dirflag},~{fpsr},~{flags}"(ptr %13, i32 %28, i32 %29, ptr %26, ptr %27) #4, !srcloc !19
  %31 = extractvalue { ptr, ptr } %30, 0
  %32 = extractvalue { ptr, ptr } %30, 1
  store ptr %31, ptr %8, align 8, !tbaa !5
  store ptr %32, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 0
}

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 = !{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 3605, i64 3624, i64 3679, i64 3734, i64 3795, i64 3831, i64 3887, i64 3944, i64 3999, i64 4054, i64 4110, i64 4165, i64 4208, i64 4263, i64 4321, i64 4381, i64 4442, i64 4497, i64 4552, i64 4609, i64 4664, i64 4723, i64 4778, i64 4833, i64 4892, i64 4947, i64 4990, i64 5045, i64 5112, i64 5167, i64 5222}


; 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 @_Z17dequantizeU8ToF3210TensorDescPhPKfS_Pf(ptr nocapture noundef readnone byval(%struct.TensorDesc) align 8 %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr nocapture noundef readonly byval(%struct.TensorDesc) align 8 %3, ptr 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 %3)
  %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) #3
  %13 = load float, ptr %2, align 4, !tbaa !5
  %14 = fdiv float 1.000000e+00, %13
  store float %14, ptr %6, align 4, !tbaa !5
  %15 = call { ptr, ptr } asm sideeffect "mov $$128, %ebx \0A\09vmovd %ebx, %xmm1                    \0A\09vbroadcastss %xmm1, %zmm2            \0A\09vbroadcastss ($2), %zmm0              \0A\09mov $3, %ebx \0A\09cmp $$0x0, %ebx                         \0A\09je 1f                                    \0A\09.align 16                              \0A\090:                                     \0A\09vpmovzxbd ($1), %zmm1            \0A\09vpsubd %zmm2, %zmm1, %zmm3          \0A\09vcvtdq2ps %zmm3, %zmm4   \0A\09vmulps %zmm4, %zmm0, %zmm5          \0A\09vmovups %zmm5, ($0)                 \0A\09add $$0x40, $0                          \0A\09add $$0x10, $1                          \0A\09dec %ebx                              \0A\09jg 0b                                  \0A\09.align 16                              \0A\091:                                     \0A\09cmp $$0x0, $4                       \0A\09je 2f                                  \0A\09kmovw %eax, %k1                      \0A\09vpmovzxbd ($1), %zmm1 {%k1}      \0A\09vpsubd %zmm2, %zmm1, %zmm3          \0A\09vcvtdq2ps %zmm3, %zmm4   \0A\09vmulps %zmm4, %zmm0, %zmm5          \0A\09vmovups %zmm5, ($0) {%k1}                 \0A\09.align 16                              \0A\092:                                     \0A\09", "=r,=r,r,r,{ax},0,1,~{k1},~{ebx},~{zmm0},~{zmm1},~{zmm2},~{zmm3},~{zmm4},~{zmm5},~{memory},~{cc},~{dirflag},~{fpsr},~{flags}"(ptr nonnull %6, i32 %8, i32 %12, ptr %4, ptr %1) #3, !srcloc !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  ret i32 0
}

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 = { 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 3605, i64 3624, i64 3679, i64 3734, i64 3795, i64 3831, i64 3887, i64 3944, i64 3999, i64 4054, i64 4110, i64 4165, i64 4208, i64 4263, i64 4321, i64 4381, i64 4442, i64 4497, i64 4552, i64 4609, i64 4664, i64 4723, i64 4778, i64 4833, i64 4892, i64 4947, i64 4990, i64 5045, i64 5112, i64 5167, i64 5222}


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