Stream: t-compiler

Topic: loop {}

nagisa (Feb 28 2019 at 18:32, on Zulip):

cc @Nikita Popov

nagisa (Feb 28 2019 at 18:32, on Zulip):

To anybody reading along, see this first

nagisa (Feb 28 2019 at 18:34, on Zulip):

@Nikita Popov what happens is that once you have

%0 = call i32 @foo();
ret i32 %0

that gets optimised out in following steps:

call void @foo()
ret i32 undef ; because foo never terminates


; foo call removed because it is readnone and its results are never used and it has no side-effects
ret i32 undef ; because foo never terminates
nagisa (Feb 28 2019 at 18:36, on Zulip):

At some point (does not matter whether it happens before or after the call removal) the return instruction also becomes unreachable

nagisa (Feb 28 2019 at 18:36, on Zulip):

and that is why you end with a function that contains a single unreachable rather than an infinite loop.

nagisa (Feb 28 2019 at 18:37, on Zulip):

making sure that such @foo is never marked as side-effect-free (which any of readnone, readonly or writeonly imply) resolves this issue in my testing

nagisa (Feb 28 2019 at 18:39, on Zulip):

Seems simple enough, right?

nagisa (Feb 28 2019 at 18:40, on Zulip):

First thing I proposed to LLVM people is to just consider noreturn attribute as a "this has side-effects" but apparently it is possible that this is not always inferred right.

Nikita Popov (Feb 28 2019 at 18:41, on Zulip):

That seems like something that should be the case regardless of whether it covers all cases...

nagisa (Feb 28 2019 at 18:43, on Zulip):

That’s how I felt as well. Then we can also somehow make sure that analysis for noreturn always runs as a dependency for the analysis for readnone and (read|write)only

Nikita Popov (Feb 28 2019 at 18:44, on Zulip):

For that purpose you're not interested in noreturn though, but in maybe noreturn. Basically pretty much any function that has a loop without known tripcount.

nagisa (Feb 28 2019 at 18:45, on Zulip):

Indeed, and that was the part that I had trouble with :slight_smile:

nagisa (Feb 28 2019 at 18:46, on Zulip):

I’m fairly unfamiliar with how that area of code works.

Last update: May 26 2020 at 13:15UTC