[llvm-dev] Change in optimisation with UB in mind

David Chisnall via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 3 04:20:02 PDT 2017


On 3 Oct 2017, at 11:37, ORiordan, Martin via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> My question is not about the validity of the optimisation - it's perfectly legitimate - but rather about whether a target can configure their TTI so as to not perform this optimisation and fall-back to using ADD instead so as to trigger integer underflow detection.

I don’t believe that this is the correct approach.  You are asking for behaviour of integer overflow in C to be well-defined as trapping (which is a valid implementation of undefined behaviour).  In LLVM, this would be represented as using the overflow-checking add intrinsic followed by a branch to a trap in the overflow case.  The back end should then lower this to a trapping add instruction.  Clang already has -ftrapv that implements almost this behaviour.

David



More information about the llvm-dev mailing list