; 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: mustprogress uwtable
define dso_local noundef i32 @_Z18dequantizeI32ToF3210TensorDescPiPKfS_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) #0 {
  %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 = load float, ptr %17, align 4, !tbaa !17
  %19 = fdiv float 1.000000e+00, %18
  store float %19, ptr %12, align 4, !tbaa !17
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load i32, ptr %11, align 4, !tbaa !14
  %23 = call { ptr, ptr } asm sideeffect "vbroadcastss ($2), %ymm2              \0A\09.align 16                              \0A\090:                                     \0A\09vmovups ($0), %ymm0                   \0A\09vcvtdq2ps %ymm0, %ymm1               \0A\09vmulps %ymm2, %ymm1, %ymm0          \0A\09vmovups %ymm0, ($1)                   \0A\09add $$0x20, $0                          \0A\09add $$0x20, $1                          \0A\09dec %ebx                              \0A\09jg 0b                                  \0A\09", "=r,=r,r,{bx},0,1,~{ymm0},~{ymm1},~{ymm2},~{memory},~{cc},~{dirflag},~{fpsr},~{flags}"(ptr %12, i32 %22, ptr %20, ptr %21) #4, !srcloc !19
  %24 = extractvalue { ptr, ptr } %23, 0
  %25 = extractvalue { ptr, ptr } %23, 1
  store ptr %24, ptr %6, align 8, !tbaa !5
  store ptr %25, ptr %8, align 8, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !14
  %27 = mul i32 %26, 8
  store i32 %27, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %28 = load i32, ptr %11, align 4, !tbaa !14
  store i32 %28, ptr %13, align 4, !tbaa !14
  br label %29

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

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %50

34:                                               ; preds = %29
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i32, ptr %13, align 4, !tbaa !14
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %35, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !14
  %40 = sitofp i32 %39 to float
  %41 = load float, ptr %12, align 4, !tbaa !17
  %42 = fmul float %40, %41
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = load i32, ptr %13, align 4, !tbaa !14
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds float, ptr %43, i64 %45
  store float %42, ptr %46, align 4, !tbaa !17
  br label %47

47:                                               ; preds = %34
  %48 = load i32, ptr %13, align 4, !tbaa !14
  %49 = add i32 %48, 1
  store i32 %49, ptr %13, align 4, !tbaa !14
  br label %29, !llvm.loop !20

50:                                               ; preds = %33
  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
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z17tensorNumElements10TensorDesc(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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 1442, i64 1484, i64 1556, i64 1628, i64 1700, i64 1772, i64 1844, i64 1916, i64 1988, i64 2060, i64 2132, i64 2204}
!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 uwtable
define dso_local noundef i32 @_Z18dequantizeI32ToF3210TensorDescPiPKfS_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 #0 {
  %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 "vbroadcastss ($2), %ymm2              \0A\09.align 16                              \0A\090:                                     \0A\09vmovups ($0), %ymm0                   \0A\09vcvtdq2ps %ymm0, %ymm1               \0A\09vmulps %ymm2, %ymm1, %ymm0          \0A\09vmovups %ymm0, ($1)                   \0A\09add $$0x20, $0                          \0A\09add $$0x20, $1                          \0A\09dec %ebx                              \0A\09jg 0b                                  \0A\09", "=r,=r,r,{bx},0,1,~{ymm0},~{ymm1},~{ymm2},~{memory},~{cc},~{dirflag},~{fpsr},~{flags}"(ptr nonnull %6, i32 %8, ptr %1, ptr %4) #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
  %umax16 = call i64 @llvm.umax.i64(i64 %17, i64 %15)
  %18 = sub nsw i64 %umax16, %16
  %min.iters.check = icmp ult i64 %18, 8
  br i1 %min.iters.check, label %.lr.ph.preheader20, label %vector.memcheck

.lr.ph.preheader20:                               ; 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 %13, 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 %13, i64 %22
  %scevgep15 = getelementptr inbounds i8, ptr %6, i64 4
  %bound0 = icmp ult ptr %scevgep, %scevgep15
  %bound1 = icmp ult ptr %6, %scevgep14
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %.lr.ph.preheader20, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.mod.vf = and i64 %umax16, 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.splatinsert18 = insertelement <4 x float> poison, float %23, i64 0
  %broadcast.splat19 = shufflevector <4 x float> %broadcast.splatinsert18, <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 i32, ptr %12, i64 %offset.idx
  %25 = getelementptr inbounds i8, ptr %24, i64 16
  %wide.load = load <4 x i32>, ptr %24, align 4, !tbaa !13
  %wide.load17 = load <4 x i32>, ptr %25, align 4, !tbaa !13
  %26 = sitofp <4 x i32> %wide.load to <4 x float>
  %27 = sitofp <4 x i32> %wide.load17 to <4 x float>
  %28 = fmul <4 x float> %broadcast.splat19, %26
  %29 = fmul <4 x float> %broadcast.splat19, %27
  %30 = getelementptr inbounds float, ptr %13, i64 %offset.idx
  %31 = getelementptr inbounds i8, ptr %30, i64 16
  store <4 x float> %28, ptr %30, align 4, !tbaa !5, !alias.scope !15, !noalias !10
  store <4 x float> %29, ptr %31, align 4, !tbaa !5, !alias.scope !15, !noalias !10
  %index.next = add nuw i64 %index, 8
  %32 = icmp eq i64 %index.next, %n.vec
  br i1 %32, label %middle.block, label %vector.body, !llvm.loop !17

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

._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.preheader20, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader20 ]
  %33 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv
  %34 = load i32, ptr %33, align 4, !tbaa !13
  %35 = sitofp i32 %34 to float
  %36 = load float, ptr %6, align 4, !tbaa !5
  %37 = fmul float %36, %35
  %38 = getelementptr inbounds float, ptr %13, i64 %indvars.iv
  store float %37, ptr %38, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = icmp ult i64 %indvars.iv.next, %15
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !21
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 1442, i64 1484, i64 1556, i64 1628, i64 1700, i64 1772, i64 1844, i64 1916, i64 1988, i64 2060, i64 2132, i64 2204}
!10 = !{!11}
!11 = distinct !{!11, !12}
!12 = distinct !{!12, !"LVerDomain"}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !18, !19, !20}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!"llvm.loop.isvectorized", i32 1}
!20 = !{!"llvm.loop.unroll.runtime.disable"}
!21 = distinct !{!21, !18, !19}


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