[llvm-dev] Poison/Undef at CodeGen level Was: [poison] is select-of-select to logic+select allowed?

Nuno Lopes via llvm-dev llvm-dev at lists.llvm.org
Mon May 29 12:31:24 PDT 2017


>> Regarding SDAG, and given that poison is already there, we would need to 
>> adopt a similar solution to the IR.  Maybe right now we can get away with 
>> it because nsw is not exploited significantly (as you say).  Just because 
>> there’s no explicit poison in SDAG, just having nsw is sufficient to 
>> cause miscompilations when combined with other transformations.
See, for example, this bug report for InstCombine regarding select+nsw: 
https://bugs.llvm.org/show_bug.cgi?id=31633
>
> Poison/Undef at the CodeGen level is a very interesting discussion! I 
> don't think there is any documentation about posion/undef at the CodeGen 
> level and I haven't discussed this much with others, so I'd like to hear 
> further feedback:
>
> - I think we should not introduce a notion of poison (which I would call 
> "delayed UB") at the SelectionDAG/CodeGen level[1]
> - Instructions either produce UB immediately, so while there are nsw/nuw 
> flags on SelectionDAG arithmetic operatiosn I think we can only assume 
> that they produce a target specific value on overflow, but not arbitrary 
> behavior. Instructions that can produce UB should marked "hasSideEffect" 
> and code motion around it be limited.
> - Typical optimization scenarios like establishing loop trip count bounds 
> for which poison/UB is helpful should not matter for CodeGen.
> - I don't have any evidence that optimizations in CodeGen require a model 
> of poison to work. If someone can given me a counter example then I'd be 
> hard pressed to disable the optimization in MI and push it towards the IR 
> level.

I'm not convinced that you need poison at SDAG/MI level either. However, you 
already have it :)
For NSW/NUW to work, undef is not enough: you need poison.  So right now 
there's already poison in SDAG; it's just that it is probably not exploited 
much more beyond folding "a+1 > a" into true or something like that. But 
poison is there for sure.
Then there's undef. It seems very useful in CodeGen; I just don't know if it 
could be replaced with poison altogether or not.

I haven't studied CodeGen as much as the IR, so I can't make any statement 
on what's the best way to go.  To do so, we need to have a list of 
transformations/optimizations that are currently done at SDAG+MI levels to 
figure out what's the best semantics.  I'm happy to help with defining the 
semantics.

Nuno 



More information about the llvm-dev mailing list