[llvm-dev] How to handle UMULO?
llvm-dev at lists.llvm.org
Wed Feb 28 11:13:23 PST 2018
If your target has a cheap count-leading-zeros instruction, you'd be able to determine whether an unsigned multiply will overflow or not, in most cases, without doing the long version of the multiplication. This is because an N-bit number times an M-bit number will produce a result that is either N+M bits wide or N+M-1 bits wide. If an N+M bit result will fit in your result type, you are guaranteed the boolean result is false; if an N+M-1 bit result does not fit in your result type, you are guaranteed the boolean result is true.
You still need to do the more complicated check in the boundary cases, I think.
From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Bruce Hoult via llvm-dev
Sent: Wednesday, February 28, 2018 5:43 AM
Cc: LLVM Developers Mailing List
Subject: Re: [llvm-dev] How to handle UMULO?
I think your users will be very upset if you don't set the boolean return value correctly :-)
Whatever work it takes to determine the correct value for it, if the user code doesn't need/use that value then the dead code will be eliminated later. But if they need that return flag then they will want it to be correct!
You may need to use a multiply instruction that returns a double-register result, or an instruction that returns only the upper half of the result. Or you might need to widen the operands and do a full double-width multiply. Or you might need to narrow the operands into two halves, do four (or three) multiplies and some shifts and adds (again detecting carry/overflow, but that's easier for addition).
It all depends on what instructions your target has.
On Wed, Feb 28, 2018 at 4:31 PM, 陳韋任 via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote:
While compiling libgcc, I find I have to deal with UMULO (overflow-aware unsigned multiplication) SDNode. UMULO returns the result of multiplication, and a boolean indicating overflow occurred or not. Our target's multiply instruction doesn't care (detect) overflow. I am wondering if I can always set the boolean to false. I am not sure about this as I see AArch64  seems trying to emulate the overflow behavior.
Wei-Ren Chen (陳韋任)
LLVM Developers mailing list
llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the llvm-dev