From 84082a3dcc94de5bf368f144f36f0ac373bb3164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20R=C3=BCsch?= Date: Thu, 12 Mar 2026 16:36:08 +0000 Subject: [PATCH 1/2] Support float round --- hugr-llvm/src/extension/float.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hugr-llvm/src/extension/float.rs b/hugr-llvm/src/extension/float.rs index e71f999dd6..37a2f2d1dd 100644 --- a/hugr-llvm/src/extension/float.rs +++ b/hugr-llvm/src/extension/float.rs @@ -103,6 +103,17 @@ fn emit_float_op<'c, H: HugrView>( .as_basic_value_enum(), ]) }), + FloatOps::fround => emit_custom_unary_op(context, args, |ctx, v, _| { + let float_ty = ctx.iw_context().f64_type().as_basic_type_enum(); + let func = get_intrinsic(ctx.get_current_module(), "llvm.round.f64", [float_ty])?; + Ok(vec![ + ctx.builder() + .build_call(func, &[v.into()], "")? + .try_as_basic_value() + .unwrap_basic() + .as_basic_value_enum(), + ]) + }), // Missing ops, not supported by inkwell FloatOps::fmax | FloatOps::fmin From cfa51a8ca406ad866378e71d558f15753345dffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20R=C3=BCsch?= Date: Mon, 16 Mar 2026 16:14:12 +0000 Subject: [PATCH 2/2] Add a testy test --- hugr-llvm/src/extension/float.rs | 1 + ...extension__float__test__fround@llvm21.snap | 21 +++++++++++++ ...loat__test__fround@pre-mem2reg@llvm21.snap | 30 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fround@llvm21.snap create mode 100644 hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fround@pre-mem2reg@llvm21.snap diff --git a/hugr-llvm/src/extension/float.rs b/hugr-llvm/src/extension/float.rs index cff5e6aaa6..b9ed6bad6f 100644 --- a/hugr-llvm/src/extension/float.rs +++ b/hugr-llvm/src/extension/float.rs @@ -226,6 +226,7 @@ mod test { #[case::fmul(FloatOps::fmul)] #[case::fdiv(FloatOps::fdiv)] #[case::fpow(FloatOps::fpow)] + #[case::fround(FloatOps::fround)] fn float_operations(mut llvm_ctx: TestContext, #[case] op: FloatOps) { let name: &str = op.into(); let hugr = test_float_op(op); diff --git a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fround@llvm21.snap b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fround@llvm21.snap new file mode 100644 index 0000000000..a7449d6799 --- /dev/null +++ b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fround@llvm21.snap @@ -0,0 +1,21 @@ +--- +source: hugr-llvm/src/extension/float.rs +assertion_line: 234 +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +define internal double @_hl.main.1(double %0) { +alloca_block: + br label %entry_block + +entry_block: ; preds = %alloca_block + %1 = call double @llvm.round.f64(double %0) + ret double %1 +} + +; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) +declare double @llvm.round.f64(double) #0 + +attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } diff --git a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fround@pre-mem2reg@llvm21.snap b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fround@pre-mem2reg@llvm21.snap new file mode 100644 index 0000000000..d46530dcd0 --- /dev/null +++ b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__float__test__fround@pre-mem2reg@llvm21.snap @@ -0,0 +1,30 @@ +--- +source: hugr-llvm/src/extension/float.rs +assertion_line: 234 +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +define internal double @_hl.main.1(double %0) { +alloca_block: + %"0" = alloca double, align 8 + %"2_0" = alloca double, align 8 + %"4_0" = alloca double, align 8 + br label %entry_block + +entry_block: ; preds = %alloca_block + store double %0, ptr %"2_0", align 8 + %"2_01" = load double, ptr %"2_0", align 8 + %1 = call double @llvm.round.f64(double %"2_01") + store double %1, ptr %"4_0", align 8 + %"4_02" = load double, ptr %"4_0", align 8 + store double %"4_02", ptr %"0", align 8 + %"03" = load double, ptr %"0", align 8 + ret double %"03" +} + +; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) +declare double @llvm.round.f64(double) #0 + +attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }