[LLVMdev] Proposal: add intrinsics for safe division

Andrew Trick atrick at apple.com
Fri May 2 13:00:07 PDT 2014


On May 2, 2014, at 12:54 PM, Eric Christopher <echristo at gmail.com> wrote:

>> I do not like the idea of doing this for safe.div at all, but we could
>> certainly add more useful semantics to patchpoint without affecting WebKit.
>> 
> 
> I'm curious about this though, what do you have in mind here about sdiv?

division + patchpoints just work the way you would expect

(1) if (division would fail) { call @patchpoint(all of my state) } else { result = a / b }

Good, this is exactly how patchpoints should be used in general. If you're not going to use the div0/overflow result, say because you deoptimize here, you would also have an unreachable on the cold path.

(2) call @safe.div; if (division-failed) { call @patchpoint(my state); unreachable }

Great! In this case, the operation we're checking already gives us the condition we need to check and it's easier to pattern match. Note that this use case alone is not a compelling reason for @safe.div. The good thing about @safe.div is that it can be used for such a wide variety of use cases and in some situations will lead to much better codegen (yes we could get performance data--I don't have it on hand).

-Andy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140502/97c20770/attachment.html>


More information about the llvm-dev mailing list