[LLVMdev] Integer divide by zero
Cameron McInally
cameron.mcinally at nyu.edu
Sun Apr 7 10:42:11 PDT 2013
On Sun, Apr 7, 2013 at 1:23 PM, Duncan Sands <baldrick at free.fr> wrote:
...
> If you want a trap you are going to have to (IMO) output IR
> instructions rather than a constant expression. For example you can
> output the
> equivalent of
> if (x == 0)
> llvm.trap() // or maybe some special trap routine
> y = whatever/x
> ... use y ...
> rather than the constant expression "whatever/x". If the optimizers can
> prove
> that x is never zero then this will be sunk back into a constant
> expression (if
> "whatever" is a constant expression).
>
Ah, that's super interesting. I'll have to give it some more thought.
Thanks for this, Duncan.
My knee-jerk reaction is that emulating hardware behaviour in software
should be avoided. At least in this specific case.
Thanks again,
Cameron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130407/d59f1117/attachment.html>
More information about the llvm-dev
mailing list