[llvm-commits] [PATCH] treat calls to noreturn functions as side effecting

Chandler Carruth chandlerc at google.com
Sat Jul 21 00:32:25 PDT 2012


On Fri, Jul 20, 2012 at 10:05 AM, Richard Osborne <richard at xmos.com> wrote:

> Currently at -O2 a call to a readonly noreturn function (e.g. a function
> consisting of while(1)) is replaced by unreachable, which seems somewhat
> nasty.


If it's readonly, it shouldn't be observable, and so it seems reasonable to
remove it.

If it has some special observable significance, it should read from a
volatile variable or otherwise cause itself to have a side-effect. This
will in turn cause the call to have the side-effect.


> The following sequence of transforms are responsible:
>
> 1) prune-eh adds unreachable after the call (since it has the noreturn
> attribute)
> 2) early-cse removes the call to the function (since it has the readonly
> attribute).
>
> This patch makes Instruction::hasSideEffect() return true for functions
> marked with the no return attribute avoid this.
> To be completely correct early-cse (and others) should be updated so that
> they only delete calls to functions that provably always return (or are
> marked as such) - see PR965. While this would be nice to fix it is also a
> much bigger slice of work.
>
> Does this patch seem reasonable?
>
> --
> Richard Osborne | XMOS
> http://www.xmos.com
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120721/531a58f7/attachment.html>


More information about the llvm-commits mailing list