; LLVM IR from huawei-noah/bolt :: compute/tensor/src/tile.ll (Z22tile_infer_output_sizeP6Tensor13TileParamSpecS0_P8ArchInfo)

; 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.TileParamSpec = type { [8 x i32], i32, i32 }
%struct.TensorDesc = type { i32, i32, i32, [20 x i32] }
%struct.ArchInfo = type { i32, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z22tile_infer_output_sizeP6Tensor13TileParamSpecS0_P8ArchInfo(ptr noundef %0, ptr noundef byval(%struct.TileParamSpec) align 8 %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.TensorDesc, align 4
  %9 = alloca %struct.TensorDesc, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.TensorDesc, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  store ptr %3, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 92, ptr %8) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN6Tensor8get_descEv(ptr dead_on_unwind writable sret(%struct.TensorDesc) align 4 %8, ptr noundef nonnull align 8 dereferenceable(32) %13)
  call void @llvm.lifetime.start.p0(i64 92, ptr %9) #3
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %8, i64 92, i1 false), !tbaa.struct !9
  %14 = getelementptr inbounds %struct.TensorDesc, ptr %8, i32 0, i32 2
  %15 = load i32, ptr %14, align 4, !tbaa !17
  %16 = getelementptr inbounds %struct.TileParamSpec, ptr %1, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !19
  %18 = icmp eq i32 %15, %17
  br i1 %18, label %19, label %54

19:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !14
  br label %20

20:                                               ; preds = %50, %19
  %21 = load i32, ptr %10, align 4, !tbaa !14
  %22 = getelementptr inbounds %struct.TileParamSpec, ptr %1, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !19
  %24 = icmp slt i32 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %53

26:                                               ; preds = %20
  %27 = getelementptr inbounds %struct.TensorDesc, ptr %8, i32 0, i32 3
  %28 = getelementptr inbounds %struct.TileParamSpec, ptr %1, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !19
  %30 = sub nsw i32 %29, 1
  %31 = load i32, ptr %10, align 4, !tbaa !14
  %32 = sub nsw i32 %30, %31
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [20 x i32], ptr %27, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !14
  %36 = getelementptr inbounds %struct.TileParamSpec, ptr %1, i32 0, i32 0
  %37 = load i32, ptr %10, align 4, !tbaa !14
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [8 x i32], ptr %36, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !14
  %41 = mul i32 %35, %40
  %42 = getelementptr inbounds %struct.TensorDesc, ptr %9, i32 0, i32 3
  %43 = getelementptr inbounds %struct.TileParamSpec, ptr %1, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !19
  %45 = sub nsw i32 %44, 1
  %46 = load i32, ptr %10, align 4, !tbaa !14
  %47 = sub nsw i32 %45, %46
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [20 x i32], ptr %42, i64 0, i64 %48
  store i32 %41, ptr %49, align 4, !tbaa !14
  br label %50

50:                                               ; preds = %26
  %51 = load i32, ptr %10, align 4, !tbaa !14
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %10, align 4, !tbaa !14
  br label %20, !llvm.loop !21

53:                                               ; preds = %25
  br label %87

54:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %55 = getelementptr inbounds %struct.TileParamSpec, ptr %1, i32 0, i32 2
  %56 = load i32, ptr %55, align 4, !tbaa !23
  %57 = icmp sge i32 %56, 0
  br i1 %57, label %58, label %61

58:                                               ; preds = %54
  %59 = getelementptr inbounds %struct.TileParamSpec, ptr %1, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !23
  br label %67

61:                                               ; preds = %54
  %62 = getelementptr inbounds %struct.TileParamSpec, ptr %1, i32 0, i32 2
  %63 = load i32, ptr %62, align 4, !tbaa !23
  %64 = getelementptr inbounds %struct.TensorDesc, ptr %8, i32 0, i32 2
  %65 = load i32, ptr %64, align 4, !tbaa !17
  %66 = add i32 %63, %65
  br label %67

67:                                               ; preds = %61, %58
  %68 = phi i32 [ %60, %58 ], [ %66, %61 ]
  store i32 %68, ptr %11, align 4, !tbaa !14
  %69 = getelementptr inbounds %struct.TensorDesc, ptr %8, i32 0, i32 2
  %70 = load i32, ptr %69, align 4, !tbaa !17
  %71 = sub i32 %70, 1
  %72 = load i32, ptr %11, align 4, !tbaa !14
  %73 = sub i32 %71, %72
  store i32 %73, ptr %11, align 4, !tbaa !14
  %74 = getelementptr inbounds %struct.TensorDesc, ptr %9, i32 0, i32 3
  %75 = load i32, ptr %11, align 4, !tbaa !14
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [20 x i32], ptr %74, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !14
  %79 = getelementptr inbounds %struct.TileParamSpec, ptr %1, i32 0, i32 0
  %80 = getelementptr inbounds [8 x i32], ptr %79, i64 0, i64 0
  %81 = load i32, ptr %80, align 8, !tbaa !14
  %82 = mul i32 %78, %81
  %83 = getelementptr inbounds %struct.TensorDesc, ptr %9, i32 0, i32 3
  %84 = load i32, ptr %11, align 4, !tbaa !14
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [20 x i32], ptr %83, i64 0, i64 %85
  store i32 %82, ptr %86, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %87

87:                                               ; preds = %67, %53
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.ArchInfo, ptr %88, i32 0, i32 0
  %90 = load i32, ptr %89, align 8, !tbaa !24
  %91 = icmp eq i32 %90, 2
  br i1 %91, label %97, label %92

92:                                               ; preds = %87
  %93 = load ptr, ptr %7, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.ArchInfo, ptr %93, i32 0, i32 0
  %95 = load i32, ptr %94, align 8, !tbaa !24
  %96 = icmp eq i32 %95, 7
  br i1 %96, label %97, label %98

97:                                               ; preds = %92, %87
  br label %98

98:                                               ; preds = %97, %92
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %9, i64 92, i1 false), !tbaa.struct !9
  call void @_ZN6Tensor6resizeE10TensorDesc(ptr noundef nonnull align 8 dereferenceable(32) %99, ptr noundef byval(%struct.TensorDesc) align 8 %12)
  call void @llvm.lifetime.end.p0(i64 92, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 92, ptr %8) #3
  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: mustprogress uwtable
declare dso_local void @_ZN6Tensor8get_descEv(ptr dead_on_unwind noalias writable sret(%struct.TensorDesc) align 4, ptr noundef nonnull align 8 dereferenceable(32)) #0 align 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) #2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Tensor6resizeE10TensorDesc(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef byval(%struct.TensorDesc) align 8) #0 align 2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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, !15, i64 8}
!18 = !{!"_ZTS10TensorDesc", !11, i64 0, !13, i64 4, !15, i64 8, !7, i64 12}
!19 = !{!20, !15, i64 32}
!20 = !{!"_ZTS13TileParamSpec", !7, i64 0, !15, i64 32, !15, i64 36}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!20, !15, i64 36}
!24 = !{!25, !26, i64 0}
!25 = !{!"_ZTS8ArchInfo", !26, i64 0, !6, i64 8}
!26 = !{!"_ZTS4Arch", !7, i64 0}


; 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.TileParamSpec = type { [8 x i32], i32, i32 }
%struct.TensorDesc = type { i32, i32, i32, [20 x i32] }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z22tile_infer_output_sizeP6Tensor13TileParamSpecS0_P8ArchInfo(ptr noundef nonnull %0, ptr nocapture noundef readonly byval(%struct.TileParamSpec) align 8 %1, ptr noundef %2, ptr nocapture noundef readnone %3) local_unnamed_addr #0 {
  %5 = alloca %struct.TensorDesc, align 4
  %6 = alloca %struct.TensorDesc, align 8
  call void @llvm.lifetime.start.p0(i64 92, ptr nonnull %5) #3
  call void @_ZN6Tensor8get_descEv(ptr dead_on_unwind nonnull writable sret(%struct.TensorDesc) align 4 %5, ptr noundef nonnull align 8 dereferenceable(32) %0)
  call void @llvm.lifetime.start.p0(i64 92, ptr nonnull %6) #3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(92) %6, ptr noundef nonnull align 4 dereferenceable(92) %5, i64 92, i1 false), !tbaa.struct !5
  %7 = getelementptr inbounds i8, ptr %5, i64 8
  %8 = load i32, ptr %7, align 4
  %9 = getelementptr inbounds i8, ptr %1, i64 32
  %10 = load i32, ptr %9, align 8, !tbaa !15
  %11 = icmp eq i32 %8, %10
  br i1 %11, label %.preheader, label %37

.preheader:                                       ; preds = %4
  %12 = icmp sgt i32 %8, 0
  br i1 %12, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %13 = getelementptr inbounds i8, ptr %5, i64 12
  %14 = getelementptr inbounds i8, ptr %6, i64 12
  %15 = zext nneg i32 %8 to i64
  %wide.trip.count = zext nneg i32 %8 to i64
  %min.iters.check = icmp ult i32 %8, 8
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %wide.trip.count, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %16 = xor i64 %index, -1
  %17 = add nsw i64 %15, %16
  %18 = getelementptr inbounds [20 x i32], ptr %13, i64 0, i64 %17
  %19 = getelementptr inbounds i8, ptr %18, i64 -12
  %20 = getelementptr inbounds i8, ptr %18, i64 -28
  %wide.load = load <4 x i32>, ptr %19, align 4, !tbaa !12
  %reverse = shufflevector <4 x i32> %wide.load, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %wide.load14 = load <4 x i32>, ptr %20, align 4, !tbaa !12
  %reverse15 = shufflevector <4 x i32> %wide.load14, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %21 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %index
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %wide.load16 = load <4 x i32>, ptr %21, align 8, !tbaa !12
  %wide.load17 = load <4 x i32>, ptr %22, align 8, !tbaa !12
  %23 = mul <4 x i32> %wide.load16, %reverse
  %24 = mul <4 x i32> %wide.load17, %reverse15
  %25 = getelementptr inbounds [20 x i32], ptr %14, i64 0, i64 %17
  %26 = getelementptr inbounds i8, ptr %25, i64 -12
  %27 = getelementptr inbounds i8, ptr %25, i64 -28
  %reverse18 = shufflevector <4 x i32> %23, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %reverse18, ptr %26, align 4, !tbaa !12
  %reverse19 = shufflevector <4 x i32> %24, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  store <4 x i32> %reverse19, ptr %27, align 4, !tbaa !12
  %index.next = add nuw i64 %index, 8
  %28 = icmp eq i64 %index.next, %n.vec
  br i1 %28, label %middle.block, label %vector.body, !llvm.loop !17

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.loopexit, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %scalar.ph ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %29 = xor i64 %indvars.iv, -1
  %30 = add nsw i64 %15, %29
  %31 = getelementptr inbounds [20 x i32], ptr %13, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = getelementptr inbounds [8 x i32], ptr %1, i64 0, i64 %indvars.iv
  %34 = load i32, ptr %33, align 4, !tbaa !12
  %35 = mul i32 %34, %32
  %36 = getelementptr inbounds [20 x i32], ptr %14, i64 0, i64 %30
  store i32 %35, ptr %36, align 4, !tbaa !12
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %scalar.ph, !llvm.loop !21

37:                                               ; preds = %4
  %38 = getelementptr inbounds i8, ptr %1, i64 36
  %39 = load i32, ptr %38, align 4
  %40 = icmp slt i32 %39, 0
  %41 = select i1 %40, i32 %8, i32 0
  %42 = add i32 %41, %39
  %43 = xor i32 %42, -1
  %44 = add i32 %8, %43
  %45 = getelementptr inbounds i8, ptr %6, i64 12
  %46 = sext i32 %44 to i64
  %47 = getelementptr inbounds [20 x i32], ptr %45, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !12
  %49 = load i32, ptr %1, align 8, !tbaa !12
  %50 = mul i32 %49, %48
  store i32 %50, ptr %47, align 4, !tbaa !12
  br label %.loopexit

.loopexit:                                        ; preds = %scalar.ph, %middle.block, %.preheader, %37
  call void @_ZN6Tensor6resizeE10TensorDesc(ptr noundef nonnull align 8 dereferenceable(32) %2, ptr noundef nonnull byval(%struct.TensorDesc) align 8 %6)
  call void @llvm.lifetime.end.p0(i64 92, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 92, ptr nonnull %5) #3
  ret i32 0
}

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Tensor8get_descEv(ptr dead_on_unwind noalias writable sret(%struct.TensorDesc) align 4, ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6Tensor6resizeE10TensorDesc(ptr noundef nonnull align 8 dereferenceable(32), ptr noundef byval(%struct.TensorDesc) align 8) local_unnamed_addr #0 align 2

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{i64 0, i64 4, !6, i64 4, i64 4, !10, i64 8, i64 4, !12, i64 12, i64 80, !14}
!6 = !{!7, !7, i64 0}
!7 = !{!"_ZTS8DataType", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!11, !11, i64 0}
!11 = !{!"_ZTS10DataFormat", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!8, !8, i64 0}
!15 = !{!16, !13, i64 32}
!16 = !{!"_ZTS13TileParamSpec", !8, i64 0, !13, i64 32, !13, i64 36}
!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, !20, !19}


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