[LLVMdev] nsw is still logically inconsistent

Andrew Trick atrick at apple.com
Wed Dec 14 13:49:06 PST 2011


On Dec 12, 2011, at 12:58 PM, Dan Gohman wrote:
> Any time the new i64 add would produce a different value than the
> original sext would have, it would be a case where the 32-bit add
> had an overflow. The nsw says that the program would have undefined
> behavior in that case if the result is used, so this should be ok.

The way I have always thought of this is that speculating an operation with side effects (udiv) cannot be safely done based on a speculative value.

So, whenever you speculate a control dependent instruction (add<nsw>), regardless of whether it has side effects, you need to transfer the control dependence to its consumers.

In an IR with explicit control dependence, that can be done literally by transferring the control edge downward in the SSA graph until you reach an operation with side-effects. In an IR without explicit control dependence, like all C compilers I've seen, you have no way to enforce this, so end up relying on each optimization to be aware and not too aggressive.

-Andy

(who used to safely speculate loads above type checks)



More information about the llvm-dev mailing list