[PATCH] D128900: [LoongArch] Add codegen support for converting between unsigned integer and floating-point
Lu Weining via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 5 02:57:40 PDT 2022
SixWeining added inline comments.
================
Comment at: llvm/test/CodeGen/LoongArch/ir-instruction/double-convert.ll:138-153
+; LA64-NEXT: pcalau12i $a0, .LCPI7_0
+; LA64-NEXT: addi.d $a0, $a0, .LCPI7_0
+; LA64-NEXT: fld.d $fa1, $a0, 0
+; LA64-NEXT: fsub.d $fa2, $fa0, $fa1
+; LA64-NEXT: ftintrz.w.d $fa2, $fa2
+; LA64-NEXT: movfr2gr.s $a0, $fa2
+; LA64-NEXT: lu12i.w $a1, -524288
----------------
xen0n wrote:
> For `f64 -> u32` conversion on LA64, isn't `ftintrz.l.d` followed by `movfr2gr.s` enough for all values within `u32`'s domain? Overflow is UB both in C and LLVM IR so we can technically ignore the (very) inconsistent behavior when input overflows.
>
> (BTW I noticed AArch64 has native support for the `fptoui` semantics by means of the `fcvtzu` insn. Hope LoongArch will gain similar niceties in a future revision...)
Thanks.
Actually we have considered the approach you mentioned. But similar to the `divide-by-zero` case, we choose the same approach as gcc what did.
And I'd like to discuss with you that is there anything missed. For example, the floating-point rounding and exception handling. `ftintrz.l.d` may not raise exception when the value is range [UINT32_MAX + 1, INT64_MAX - 1]. Not sure whehter we need to manually raise an exception.
@xry111 Hope to see inputs from you, too.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128900/new/
https://reviews.llvm.org/D128900
More information about the llvm-commits
mailing list