; LLVM IR from gem5/gem5 :: ext/softfloat (f64_to_f32)

; 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.float32_t = type { i32 }
%struct.float64_t = type { i64 }
%union.ui64_f64 = type { i64 }
%struct.commonNaN = type { i8 }
%union.ui32_f32 = type { i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @f64_to_f32(i64 %0) #0 {
  %2 = alloca %struct.float32_t, align 4
  %3 = alloca %struct.float64_t, align 8
  %4 = alloca %union.ui64_f64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca %struct.commonNaN, align 1
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca %union.ui32_f32, align 4
  %13 = alloca i32, align 4
  %14 = getelementptr inbounds %struct.float64_t, ptr %3, i32 0, i32 0
  store i64 %0, ptr %14, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %3, i64 8, i1 false), !tbaa.struct !5
  %15 = load i64, ptr %4, align 8, !tbaa !10
  store i64 %15, ptr %5, align 8, !tbaa !6
  %16 = load i64, ptr %5, align 8, !tbaa !6
  %17 = lshr i64 %16, 63
  %18 = icmp ne i64 %17, 0
  %19 = zext i1 %18 to i8
  store i8 %19, ptr %6, align 1, !tbaa !11
  %20 = load i64, ptr %5, align 8, !tbaa !6
  %21 = lshr i64 %20, 52
  %22 = and i64 %21, 2047
  store i64 %22, ptr %7, align 8, !tbaa !6
  %23 = load i64, ptr %5, align 8, !tbaa !6
  %24 = and i64 %23, 4503599627370495
  store i64 %24, ptr %8, align 8, !tbaa !6
  %25 = load i64, ptr %7, align 8, !tbaa !6
  %26 = icmp eq i64 %25, 2047
  br i1 %26, label %27, label %45

27:                                               ; preds = %1
  %28 = load i64, ptr %8, align 8, !tbaa !6
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %36

30:                                               ; preds = %27
  %31 = load i64, ptr %5, align 8, !tbaa !6
  %32 = and i64 %31, 2251799813685248
  %33 = icmp ne i64 %32, 0
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  call void @softfloat_raiseFlags(i8 noundef zeroext 16)
  br label %35

35:                                               ; preds = %34, %30
  store i64 2143289344, ptr %10, align 8, !tbaa !6
  br label %44

36:                                               ; preds = %27
  %37 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %38 = trunc i8 %37 to i1
  %39 = zext i1 %38 to i32
  %40 = shl i32 %39, 31
  %41 = add i32 %40, 2139095040
  %42 = add i32 %41, 0
  %43 = zext i32 %42 to i64
  store i64 %43, ptr %10, align 8, !tbaa !6
  br label %44

44:                                               ; preds = %36, %35
  br label %69

45:                                               ; preds = %1
  %46 = load i64, ptr %8, align 8, !tbaa !6
  %47 = call i64 @softfloat_shortShiftRightJam64(i64 noundef %46, i8 noundef zeroext 22)
  store i64 %47, ptr %11, align 8, !tbaa !6
  %48 = load i64, ptr %7, align 8, !tbaa !6
  %49 = load i64, ptr %11, align 8, !tbaa !6
  %50 = or i64 %48, %49
  %51 = icmp ne i64 %50, 0
  br i1 %51, label %60, label %52

52:                                               ; preds = %45
  %53 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %54 = trunc i8 %53 to i1
  %55 = zext i1 %54 to i32
  %56 = shl i32 %55, 31
  %57 = add i32 %56, 0
  %58 = add i32 %57, 0
  %59 = zext i32 %58 to i64
  store i64 %59, ptr %10, align 8, !tbaa !6
  br label %69

60:                                               ; preds = %45
  %61 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %62 = trunc i8 %61 to i1
  %63 = load i64, ptr %7, align 8, !tbaa !6
  %64 = sub nsw i64 %63, 897
  %65 = load i64, ptr %11, align 8, !tbaa !6
  %66 = or i64 %65, 1073741824
  %67 = call i32 @softfloat_roundPackToF32(i1 noundef zeroext %62, i64 noundef %64, i64 noundef %66)
  %68 = getelementptr inbounds %struct.float32_t, ptr %2, i32 0, i32 0
  store i32 %67, ptr %68, align 4
  store i32 1, ptr %13, align 4
  br label %72

69:                                               ; preds = %52, %44
  %70 = load i64, ptr %10, align 8, !tbaa !6
  %71 = trunc i64 %70 to i32
  store i32 %71, ptr %12, align 4, !tbaa !10
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 %12, i64 4, i1 false), !tbaa.struct !15
  store i32 1, ptr %13, align 4
  br label %72

72:                                               ; preds = %69, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %73 = getelementptr inbounds %struct.float32_t, ptr %2, i32 0, i32 0
  %74 = load i32, ptr %73, align 4
  ret i32 %74
}

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

declare void @softfloat_raiseFlags(i8 noundef zeroext) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @softfloat_shortShiftRightJam64(i64 noundef, i8 noundef zeroext) #4

declare i32 @softfloat_roundPackToF32(i1 noundef zeroext, i64 noundef, i64 noundef) #3

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { inlinehint 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 #5 = { 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 8, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{i64 0, i64 4, !16}
!16 = !{!17, !17, i64 0}
!17 = !{!"int", !8, 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @f64_to_f32(i64 %0) local_unnamed_addr #0 {
  %2 = icmp slt i64 %0, 0
  %3 = lshr i64 %0, 52
  %4 = and i64 %3, 2047
  %5 = and i64 %0, 4503599627370495
  %6 = icmp eq i64 %4, 2047
  br i1 %6, label %7, label %14

7:                                                ; preds = %1
  %.not20 = icmp eq i64 %5, 0
  br i1 %.not20, label %11, label %8

8:                                                ; preds = %7
  %9 = and i64 %0, 2251799813685248
  %.not22 = icmp eq i64 %9, 0
  br i1 %.not22, label %10, label %23

10:                                               ; preds = %8
  tail call void @softfloat_raiseFlags(i8 noundef zeroext 16) #3
  br label %23

11:                                               ; preds = %7
  %sh.diff21 = lshr exact i64 %0, 32
  %12 = and i64 %sh.diff21, 2147483648
  %13 = or disjoint i64 %12, 2139095040
  br label %23

14:                                               ; preds = %1
  %15 = tail call i64 @softfloat_shortShiftRightJam64(i64 noundef %5, i8 noundef zeroext 22)
  %16 = or i64 %15, %4
  %.not = icmp eq i64 %16, 0
  br i1 %.not, label %17, label %19

17:                                               ; preds = %14
  %sh.diff = lshr i64 %0, 32
  %18 = and i64 %sh.diff, 2147483648
  br label %23

19:                                               ; preds = %14
  %20 = add nsw i64 %4, -897
  %21 = or i64 %15, 1073741824
  %22 = tail call i32 @softfloat_roundPackToF32(i1 noundef zeroext %2, i64 noundef %20, i64 noundef %21) #3
  br label %25

23:                                               ; preds = %8, %10, %11, %17
  %.0 = phi i64 [ %13, %11 ], [ %18, %17 ], [ 2143289344, %10 ], [ 2143289344, %8 ]
  %24 = trunc nuw i64 %.0 to i32
  br label %25

25:                                               ; preds = %23, %19
  %.sroa.018.0 = phi i32 [ %24, %23 ], [ %22, %19 ]
  ret i32 %.sroa.018.0
}

declare void @softfloat_raiseFlags(i8 noundef zeroext) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @softfloat_shortShiftRightJam64(i64 noundef, i8 noundef zeroext) local_unnamed_addr #2

declare i32 @softfloat_roundPackToF32(i1 noundef zeroext, i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 = { "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 = { inlinehint 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 = { 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass