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

; 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.float16_t = type { i16 }
%struct.float64_t = type { i64 }
%union.ui64_f64 = type { i64 }
%struct.commonNaN = type { i8 }
%union.ui16_f16 = type { i16 }

; Function Attrs: nounwind uwtable
define dso_local i16 @f64_to_f16(i64 %0) #0 {
  %2 = alloca %struct.float16_t, align 2
  %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.ui16_f16, align 2
  %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 2, 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 %46

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 32256, ptr %10, align 8, !tbaa !6
  br label %45

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 i16
  %40 = zext i16 %39 to i32
  %41 = shl i32 %40, 15
  %42 = add nsw i32 %41, 31744
  %43 = add nsw i32 %42, 0
  %44 = sext i32 %43 to i64
  store i64 %44, ptr %10, align 8, !tbaa !6
  br label %45

45:                                               ; preds = %36, %35
  br label %71

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

53:                                               ; preds = %46
  %54 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %55 = trunc i8 %54 to i1
  %56 = zext i1 %55 to i16
  %57 = zext i16 %56 to i32
  %58 = shl i32 %57, 15
  %59 = add nsw i32 %58, 0
  %60 = add nsw i32 %59, 0
  %61 = sext i32 %60 to i64
  store i64 %61, ptr %10, align 8, !tbaa !6
  br label %71

62:                                               ; preds = %46
  %63 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %64 = trunc i8 %63 to i1
  %65 = load i64, ptr %7, align 8, !tbaa !6
  %66 = sub nsw i64 %65, 1009
  %67 = load i64, ptr %11, align 8, !tbaa !6
  %68 = or i64 %67, 16384
  %69 = call i16 @softfloat_roundPackToF16(i1 noundef zeroext %64, i64 noundef %66, i64 noundef %68)
  %70 = getelementptr inbounds %struct.float16_t, ptr %2, i32 0, i32 0
  store i16 %69, ptr %70, align 2
  store i32 1, ptr %13, align 4
  br label %74

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

74:                                               ; preds = %71, %62
  call void @llvm.lifetime.end.p0(i64 2, 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
  %75 = getelementptr inbounds %struct.float16_t, ptr %2, i32 0, i32 0
  %76 = load i16, ptr %75, align 2
  ret i16 %76
}

; 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 i16 @softfloat_roundPackToF16(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 2, !16}
!16 = !{!17, !17, i64 0}
!17 = !{!"short", !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 i16 @f64_to_f16(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, 48
  %12 = and i64 %sh.diff21, 32768
  %13 = or disjoint i64 %12, 31744
  br label %23

14:                                               ; preds = %1
  %15 = tail call i64 @softfloat_shortShiftRightJam64(i64 noundef %5, i8 noundef zeroext 38)
  %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, 48
  %18 = and i64 %sh.diff, 32768
  br label %23

19:                                               ; preds = %14
  %20 = add nsw i64 %4, -1009
  %21 = or i64 %15, 16384
  %22 = tail call i16 @softfloat_roundPackToF16(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 ], [ 32256, %10 ], [ 32256, %8 ]
  %24 = trunc nuw i64 %.0 to i16
  br label %25

25:                                               ; preds = %23, %19
  %.sroa.018.0 = phi i16 [ %24, %23 ], [ %22, %19 ]
  ret i16 %.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 i16 @softfloat_roundPackToF16(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