[LLVMdev] RFC: Proposal for Poison Semantics

Bruce Hoult bruce at hoult.org
Wed Jan 28 02:05:06 PST 2015


On Wed, Jan 28, 2015 at 7:18 PM, Mehdi Amini <mehdi.amini at apple.com> wrote:

>
> > On Jan 27, 2015, at 6:50 PM, David Majnemer <david.majnemer at gmail.com>
> wrote:
> > Let's start with a concrete motivating example in C:
> > ```
> > int isSumGreater(int a, int b) {
> >   return a + b > a;
> > }
> > ```
> >
> > The C specification permits us to optimize the comparison in
> `isSumGreater` to `b > 0` because signed overflow results in undefined
> behavior.  A reasonable translation of `isSumGreater` to LLVM IR could be:
>
> Typo:
>    to `b > 0`
> should be
>   to `a + b > 0`
> IIUC.
>

Let a = -10 and b = 1

a + b > a  ===  -10 + 1 > -10  ===  -9 > -10  === true

b > 0 === 1 > 0 === true

All good.

Your version:

a + b > 0  === -10 + 1 > 0 === -9 > 0 === false

Small problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150128/1b55302a/attachment.html>


More information about the llvm-dev mailing list