[llvm-dev] RFC: Killing undef and spreading poison

Sanjoy Das via llvm-dev llvm-dev at lists.llvm.org
Tue Jun 6 22:09:51 PDT 2017


Hi Peter,

On Mon, Jun 5, 2017 at 3:56 PM, Peter Lawrence
<peterl95124 at sbcglobal.net> wrote:
> Sanjay,
>             Your original example showed end-to-end-miscompilation,
> After a sequence of transformations,
> Where “undefined behavior” is a part of the problem.
>
>
> My question is can you show some additional examples that do not rely on
> “nsw” or “nuw” ?

I still don't understand you -- I don't see how an example of a
miscompile that does not involve nsw/nuw is relevant here -- while I'm
sure LLVM has generic bugs, such a miscompile will not illustrate
anything about the nature of poison as it is implemented in LLVM
today.

If you're asking for an example where the original program does not
have UB, that is precisely what I was trying to illustrate in the
original example.  In

 > for (...) {
 > if (condition){
 > i32 prod = x *nsw y
 > i64 prod.sext = sext prod to i64
 > i64 t = K `udiv` (-1 + (sum.prod >> 32))
 > use(t)
 > }
 > }

the program does *not* have UB if "condition" implies that "x * y does
not sign overflow".  For instance "condition" could be
"__builtin_smul_overflow(x, y, &res)", in which case

 a. The program does not have UB
 b. Even if prod was not marked nsw, it would have been legal for LLVM
to infer it


-- Sanjoy


More information about the llvm-dev mailing list