; LLVM IR from huawei-noah/bolt :: compute/tensor/src/cpu/x86/int8/avx (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: 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 float, align 4
  %13 = alloca i32, 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, 8
  store i32 %16, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds float, ptr %17, i64 0
  %19 = load float, ptr %18, align 4, !tbaa !17
  %20 = fdiv float 1.000000e+00, %19
  store float %20, ptr %12, align 4, !tbaa !17
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i32, ptr %11, align 4, !tbaa !14
  %24 = call { ptr, ptr } asm sideeffect "mov $$128, %ebx \0A\09vmovd %ebx, %xmm1                    \0A\09vbroadcastss %xmm1, %ymm2            \0A\09vbroadcastss ($2), %ymm0              \0A\09mov $3, %ebx \0A\09cmp $$0x0, %ebx                         \0A\09je 1f                                    \0A\09.align 16                              \0A\090:                                     \0A\09vpmovzxbd ($1), %ymm1            \0A\09vpsubd %ymm2, %ymm1, %ymm3          \0A\09vcvtdq2ps %ymm3, %ymm4   \0A\09vmulps %ymm4, %ymm0, %ymm5          \0A\09vmovups %ymm5, ($0)                 \0A\09add $$0x20, $0                          \0A\09add $$0x8, $1                          \0A\09dec %ebx                              \0A\09jg 0b                                  \0A\09.align 16                              \0A\091:                                     \0A\09", "=r,=r,r,r,0,1,~{ebx},~{ymm0},~{ymm1},~{ymm2},~{ymm3},~{ymm4},~{ymm5},~{memory},~{cc},~{dirflag},~{fpsr},~{flags}"(ptr %12, i32 %23, ptr %21, ptr %22) #4, !srcloc !19
  %25 = extractvalue { ptr, ptr } %24, 0
  %26 = extractvalue { ptr, ptr } %24, 1
  store ptr %25, ptr %8, align 8, !tbaa !5
  store ptr %26, ptr %6, align 8, !tbaa !5
  %27 = load i32, ptr %11, align 4, !tbaa !14
  %28 = mul i32 %27, 8
  store i32 %28, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %29 = load i32, ptr %11, align 4, !tbaa !14
  store i32 %29, ptr %13, align 4, !tbaa !14
  br label %30

30:                                               ; preds = %49, %5
  %31 = load i32, ptr %13, align 4, !tbaa !14
  %32 = load i32, ptr %9, align 4, !tbaa !14
  %33 = icmp ult i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %52

35:                                               ; preds = %30
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %13, align 4, !tbaa !14
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !16
  %41 = uitofp i8 %40 to float
  %42 = fsub float %41, 1.280000e+02
  %43 = load float, ptr %12, align 4, !tbaa !17
  %44 = fmul float %42, %43
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = load i32, ptr %13, align 4, !tbaa !14
  %47 = zext i32 %46 to i64
  %48 = getelementptr inbounds float, ptr %45, i64 %47
  store float %44, ptr %48, align 4, !tbaa !17
  br label %49

49:                                               ; preds = %35
  %50 = load i32, ptr %13, align 4, !tbaa !14
  %51 = add i32 %50, 1
  store i32 %51, ptr %13, align 4, !tbaa !14
  br label %30, !llvm.loop !20

52:                                               ; preds = %34
  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 2871, i64 2890, i64 2945, i64 3000, i64 3061, i64 3096, i64 3152, i64 3209, i64 3264, i64 3319, i64 3375, i64 3430, i64 3473, i64 3528, i64 3586, i64 3646, i64 3706, i64 3761, i64 3816, i64 3873, i64 3928}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%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: 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, 3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  %9 = load float, ptr %2, align 4, !tbaa !5
  %10 = fdiv float 1.000000e+00, %9
  store float %10, ptr %6, align 4, !tbaa !5
  %11 = call { ptr, ptr } asm sideeffect "mov $$128, %ebx \0A\09vmovd %ebx, %xmm1                    \0A\09vbroadcastss %xmm1, %ymm2            \0A\09vbroadcastss ($2), %ymm0              \0A\09mov $3, %ebx \0A\09cmp $$0x0, %ebx                         \0A\09je 1f                                    \0A\09.align 16                              \0A\090:                                     \0A\09vpmovzxbd ($1), %ymm1            \0A\09vpsubd %ymm2, %ymm1, %ymm3          \0A\09vcvtdq2ps %ymm3, %ymm4   \0A\09vmulps %ymm4, %ymm0, %ymm5          \0A\09vmovups %ymm5, ($0)                 \0A\09add $$0x20, $0                          \0A\09add $$0x8, $1                          \0A\09dec %ebx                              \0A\09jg 0b                                  \0A\09.align 16                              \0A\091:                                     \0A\09", "=r,=r,r,r,0,1,~{ebx},~{ymm0},~{ymm1},~{ymm2},~{ymm3},~{ymm4},~{ymm5},~{memory},~{cc},~{dirflag},~{fpsr},~{flags}"(ptr nonnull %6, i32 %8, ptr %4, ptr %1) #4, !srcloc !9
  %12 = extractvalue { ptr, ptr } %11, 0
  %13 = extractvalue { ptr, ptr } %11, 1
  %14 = and i32 %7, 7
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %5
  %15 = zext i32 %7 to i64
  %16 = and i64 %15, 4294967288
  %17 = or disjoint i64 %16, 1
  %umax21 = call i64 @llvm.umax.i64(i64 %17, i64 %15)
  %18 = sub nsw i64 %umax21, %16
  %min.iters.check = icmp ult i64 %18, 12
  br i1 %min.iters.check, label %.lr.ph.preheader25, label %vector.memcheck

.lr.ph.preheader25:                               ; preds = %middle.block, %vector.memcheck, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ %16, %vector.memcheck ], [ %16, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.memcheck:                                  ; preds = %.lr.ph.preheader
  %19 = shl nuw nsw i64 %15, 2
  %20 = and i64 %19, 17179869152
  %scevgep = getelementptr i8, ptr %12, i64 %20
  %21 = or disjoint i64 %16, 1
  %umax = call i64 @llvm.umax.i64(i64 %21, i64 %15)
  %22 = shl nuw nsw i64 %umax, 2
  %scevgep14 = getelementptr i8, ptr %12, i64 %22
  %scevgep15 = getelementptr i8, ptr %13, i64 %16
  %scevgep16 = getelementptr i8, ptr %13, i64 %umax
  %scevgep17 = getelementptr inbounds i8, ptr %6, i64 4
  %bound0 = icmp ult ptr %scevgep, %scevgep16
  %bound1 = icmp ult ptr %scevgep15, %scevgep14
  %found.conflict = and i1 %bound0, %bound1
  %bound018 = icmp ult ptr %scevgep, %scevgep17
  %bound119 = icmp ult ptr %6, %scevgep14
  %found.conflict20 = and i1 %bound018, %bound119
  %conflict.rdx = or i1 %found.conflict, %found.conflict20
  br i1 %conflict.rdx, label %.lr.ph.preheader25, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.mod.vf = and i64 %umax21, 7
  %n.vec = sub nsw i64 %18, %n.mod.vf
  %ind.end = add nsw i64 %16, %n.vec
  %23 = load float, ptr %6, align 4, !tbaa !5, !alias.scope !10
  %broadcast.splatinsert23 = insertelement <4 x float> poison, float %23, i64 0
  %broadcast.splat24 = shufflevector <4 x float> %broadcast.splatinsert23, <4 x float> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = add i64 %16, %index
  %24 = getelementptr inbounds i8, ptr %13, i64 %offset.idx
  %25 = getelementptr inbounds i8, ptr %24, i64 4
  %wide.load = load <4 x i8>, ptr %24, align 1, !tbaa !13, !alias.scope !14
  %wide.load22 = load <4 x i8>, ptr %25, align 1, !tbaa !13, !alias.scope !14
  %26 = uitofp <4 x i8> %wide.load to <4 x float>
  %27 = uitofp <4 x i8> %wide.load22 to <4 x float>
  %28 = fadd <4 x float> %26, <float -1.280000e+02, float -1.280000e+02, float -1.280000e+02, float -1.280000e+02>
  %29 = fadd <4 x float> %27, <float -1.280000e+02, float -1.280000e+02, float -1.280000e+02, float -1.280000e+02>
  %30 = fmul <4 x float> %broadcast.splat24, %28
  %31 = fmul <4 x float> %broadcast.splat24, %29
  %32 = getelementptr inbounds float, ptr %12, i64 %offset.idx
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  store <4 x float> %30, ptr %32, align 4, !tbaa !5, !alias.scope !16, !noalias !18
  store <4 x float> %31, ptr %33, align 4, !tbaa !5, !alias.scope !16, !noalias !18
  %index.next = add nuw i64 %index, 8
  %34 = icmp eq i64 %index.next, %n.vec
  br i1 %34, label %middle.block, label %vector.body, !llvm.loop !19

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.mod.vf, 0
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader25

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  ret i32 0

.lr.ph:                                           ; preds = %.lr.ph.preheader25, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader25 ]
  %35 = getelementptr inbounds i8, ptr %13, i64 %indvars.iv
  %36 = load i8, ptr %35, align 1, !tbaa !13
  %37 = uitofp i8 %36 to float
  %38 = fadd float %37, -1.280000e+02
  %39 = load float, ptr %6, align 4, !tbaa !5
  %40 = fmul float %39, %38
  %41 = getelementptr inbounds float, ptr %12, i64 %indvars.iv
  store float %40, ptr %41, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %42 = icmp ult i64 %indvars.iv.next, %15
  br i1 %42, label %.lr.ph, label %._crit_edge, !llvm.loop !23
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 2871, i64 2890, i64 2945, i64 3000, i64 3061, i64 3096, i64 3152, i64 3209, i64 3264, i64 3319, i64 3375, i64 3430, i64 3473, i64 3528, i64 3586, i64 3646, i64 3706, i64 3761, i64 3816, i64 3873, i64 3928}
!10 = !{!11}
!11 = distinct !{!11, !12}
!12 = distinct !{!12, !"LVerDomain"}
!13 = !{!7, !7, i64 0}
!14 = !{!15}
!15 = distinct !{!15, !12}
!16 = !{!17}
!17 = distinct !{!17, !12}
!18 = !{!15, !11}
!19 = distinct !{!19, !20, !21, !22}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!"llvm.loop.isvectorized", i32 1}
!22 = !{!"llvm.loop.unroll.runtime.disable"}
!23 = distinct !{!23, !20, !21}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass