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

Daniel Berlin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 23 17:30:24 PST 2017


dberlin added a comment.

In https://reviews.llvm.org/D29092#685299, @efriedma wrote:

> > GVNHoist: 935 checks if Call->mayThrow() which checks if the call will unwind or not IIUC.
>
> mayThrow() isn't really helpful here; consider:
>
>   #include <stdlib.h>
>   void f() { exit(0); }
>   void (*ff)() = f;
>   int r;
>   int g(int x, int a) {
>     if (a) {
>       r = 999 / x;
>       return 3;
>     } else {
>       ff();
>       return 999 / x;
>     }
>   }
>   int (*gg)(int, int) = g;
>   int main() {
>     gg(0, 0);
>   }
>


Gcc eliminates/hoist this one too if you make the function pointer local, or compile in whole-program mode.

GVNHoist only hoists hings executed on all paths, it does not create executions on paths they were not executed on before.
Thus, it will have precisely the same behavior as gcc .

At least, if implemented correctly.


https://reviews.llvm.org/D29092





More information about the llvm-commits mailing list