[PATCH] D29092: PR31729: [GVNHoist] Don't hoist unsafe scalars at -Oz

Mehdi AMINI via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 23 16:41:09 PST 2017


mehdi_amini added a comment.

In https://reviews.llvm.org/D29092#685265, @dberlin wrote:

> (Though i quibble with this part:
>
>   // The called function could have undefined behavior or
>   // side-effects, even if marked readnone nounwind.
>   
>
> I'm not sure what we think those side effects are, but we should be modeling them or ignoring them.


Divide by zero?

The only current solution we have for this now is to be conservative with respect to calls. There is a new attribute implemented here https://reviews.llvm.org/D20116 that will help making it "less conservative", by allowing to speculate if there can't be UB whatever arguments are passed to the function. 
This wouldn't capture this for instance:

  // can be speculated if we know that the argument is never 0
  int inverse(int n) { return 1/n; }

>From your GCC experience, do you have a suggestion how to address/model this?


https://reviews.llvm.org/D29092





More information about the llvm-commits mailing list