Hi Cameron, On 06/04/13 22:52, Cameron McInally wrote:> On Sat, Apr 6, 2013 at 3:22 PM, Jeff Bezanson <jeff.bezanson at gmail.com > <mailto:jeff.bezanson at gmail.com>> wrote: > > A division intrinsic with defined behavior on all arguments would be > awesome! Thanks for considering this. > > > 'Tis a good compromise. If there are no objections/concerns, I would like to > move forward with it.can't front-ends implement this themselves using the "select" constant expression? For example, rather than dividing by "x" you can divide by "x == 0 ? 1 : x". Ciao, Duncan.
Hey Duncan, On Sun, Apr 7, 2013 at 11:22 AM, Duncan Sands <baldrick at free.fr> wrote: ...> can't front-ends implement this themselves using the "select" constant > expression? For example, rather than dividing by "x" you can divide by > "x == 0 ? 1 : x". >I'm not sure that I follow. I would like to see the division by zero execute and trap at runtime. For example, x = 2/0. It looks like your suggestion would generate the expression 2/1, which wouldn't trap as expected. Am I misinterpreting your suggestion? Thanks, Cameron P.S. Is it your intention to hide the simple constant expression from the constant folder? I.e. (x == 0) ? 0 : x. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130407/c885822c/attachment.html>
Hi Cameron, On 07/04/13 18:20, Cameron McInally wrote:> Hey Duncan, > > On Sun, Apr 7, 2013 at 11:22 AM, Duncan Sands <baldrick at free.fr > <mailto:baldrick at free.fr>> wrote: > ... > > can't front-ends implement this themselves using the "select" constant > expression? For example, rather than dividing by "x" you can divide by > "x == 0 ? 1 : x". > > > I'm not sure that I follow. I would like to see the division by zero execute and > trap at runtime. > > For example, x = 2/0. It looks like your suggestion would generate the > expression 2/1, which wouldn't trap as expected. > > Am I misinterpreting your suggestion?I didn't realize you wanted a trap, I just thought you wanted to avoid undefined behaviour. 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). Ciao, Duncan.> > Thanks, > Cameron > > P.S. Is it your intention to hide the simple constant expression from the > constant folder? I.e. (x == 0) ? 0 : x.