[LLVMdev] Deriving undefined behavior from nsw/inbounds/poison for scalar evolution

Sanjoy Das sanjoy at playingwithpointers.com
Wed Jul 1 00:11:11 PDT 2015


> To make sure that I understand correctly, are you suggesting making
> the nuw (and similar) flags part of the key when looking up an SCEV in
> the UniqueSCEVs member variable on ScalarEvolution? That way, an

Yes.

> instruction with nuw and one without will not map to the same SCEV
> unless the nuw can be inferred in some other way. Sounds good to me,

Yes.

> I'm happy to go with either one of that or inferring UB from poison.

Just to be clear, it is not clear to me which approach is better.  I
was only offering a potential alternative.

> Adding the flags to the key/identity does break the idea that
> mathematically equivalent expressions should cancel if
> subtracted. Andrew Trick wrote something about that previously:
>
>   http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20141215/249390.html

It depends on what sort of semantics you assign to an overflowing
<nsw> scev expression.  If such an overflowing expression is supposed
to produce poison, then I think you can cancel "(a +nsw b) - (a + b)"
since "poison - <anything>" == "poison" --> can be replaced with "0".

Another way to look at this is that it should always be legal for the
compiler to drop <nsw> to do a simplification.

-- Sanjoy



More information about the llvm-dev mailing list