[LLVMdev] Proposal: add intrinsics for safe division
Andrew Trick
atrick at apple.com
Fri May 2 16:46:09 PDT 2014
On May 2, 2014, at 4:25 PM, Philip Reames <listmail at philipreames.com> wrote:
>
> I'm still not happy with hiding the explicit control flow, but I can achieve the same effect as:
> if( div by zero ) throw
> (r, o, d) = safe.div(a,b);
> if( o ) {
> r = a;
> }
>
> i.e. emit a separate guard branch for the interesting condition and not utilize the value from the safe div.
Oh, I was just assuming you would deopt on either div-by-zero or overflow in order to optimize the common case.
So, the point of safe.div is that you don’t need control flow in the IR except to indicate the throw.
(r, o, d) = safe.div(a,b)
if (d) { patchpoint(throw, state) }
You could also explicitly check div-by-zero but it would be harder to fold away that extra check during lowering.
-Andy
>
> Assuming the codegen patterns are right, this should give me options for expressing all of the patterns I might like to explore.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140502/6517cf61/attachment.html>
More information about the llvm-dev
mailing list