Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 13419 - Remove comma expression in std.uni #2485

Merged
merged 1 commit into from Sep 10, 2014

Conversation

schuetzm
Copy link
Contributor

@schuetzm schuetzm commented Sep 3, 2014

This is a patch by Ketmar Dark:
https://issues.dlang.org/show_bug.cgi?id=13419

@quickfur
Copy link
Member

quickfur commented Sep 3, 2014

LGTM

@DmitryOlshansky
Copy link
Member

Yeah, thanks guys... Bored yawn.
Now it would be awesome if any of you have an idea how to bring inlining of these functions back (in DMD) without comma expression. :)

@schuetzm
Copy link
Contributor Author

schuetzm commented Sep 4, 2014

Yes, something really needs to be done about this annoying restriction. But it needs to be done in DMD. We should probably put more non-inlineable code into Phobos, to raise the pressure ;-)

@DmitryOlshansky
Copy link
Member

@schuetzm I agree. The problem is it's users who would loose on performance, while we shuffle work between compiler and phobos teams.

So ideally it's first fix the compiler, then rewrite code. But alas compiler guys would say that since everybody in the know already writes code using comma to get inlining, it's not a top priority. Here we go catch-22.

@yebblies
Copy link
Member

yebblies commented Sep 4, 2014

So ideally it's first fix the compiler, then rewrite code.

Agreed. I'm a little surprised to hear it doesn't inline this already.

But alas compiler guys would say that since everybody in the know already writes code using comma to get inlining, it's not a top priority. Here we go catch-22.

We would?

@DmitryOlshansky
Copy link
Member

But alas compiler guys would say that since everybody in the know already writes code using comma to get inlining, it's not a top priority. Here we go catch-22.

We would?

@yebblies Well, okay maybe they won't :) I wish to be proven wrong, it come up before, not a single time. There seems to always be some pressing matters far greater then inlining of basic if statements and multiple early returns. It especially hurts functions that return something.

@quickfur
Copy link
Member

quickfur commented Sep 4, 2014

DMD's inlining is really poor. It gives up too easily. I always find that gdc's inlining is far superior.

@mihails-strasuns
Copy link

I am marking this as blocked until inlining issue is fixed in DMD.

@yebblies
Copy link
Member

yebblies commented Sep 6, 2014

Looking at the first function, this can be inlined

char truncate()(char ch) pure @safe
{
    ch -= 0x80;
   return ch < 0x40 ? ch : (badEncoding(), cast(char)0);
}

But this can't:

char truncate()(char ch) pure @safe
{
    ch -= 0x80;
    if (ch < 0x40) return ch;
    badEncoding();
    return cast(char)0);
}

But this one can:

char truncate()(char ch) pure @safe
{
    ch -= 0x80;
    if (ch < 0x40)
        return ch;
    else
    {
        badEncoding();
        return cast(char)0);
    }
}

ie The if-and-fallthough means the inliner's primitive flow analysis can't tell that function 2 always returns and can therefore be turned into an expression.
To detect this, the inliner needs a) a canonicalization pass to generate if-else blocks everywhere, b) a more sophisticated return-detection algorithm or c) to be moved into the backend.

@DmitryOlshansky Of the other functions modified in this pull, which ones are actually prevented from being inlined?

@DmitryOlshansky
Copy link
Member

@yebblies I'll try to use the if/else wokraround and see if there any other patterns that can't be re-written or problematic.

@quickfur
Copy link
Member

quickfur commented Sep 8, 2014

I still think the inliner should be improved. But at least that shouldn't block this PR anymore.

@quickfur quickfur removed the Blocked label Sep 8, 2014
@quickfur
Copy link
Member

quickfur commented Sep 8, 2014

@schuetzm Please update code to if/else branch to ensure inlining in dmd.

@schuetzm
Copy link
Contributor Author

schuetzm commented Sep 8, 2014

I changed all except the one in Impl.lookup, where the else block would encompass the entire remaining function.

@quickfur
Copy link
Member

quickfur commented Sep 8, 2014

Looks reasonable; Impl.lookup is a huge function anyway and I don't think anyone would expect it to be inlined. LGTM, I'll wait a bit for other reviewers (esp. @DmitryOlshansky ) to take a look before merging.

@mihails-strasuns
Copy link

Yep, it is up to Dmitry to call it merge-ready

@DmitryOlshansky
Copy link
Member

Aye-aye. I'll just run my benchmarks with and without this patch. Somewhat busy at the moment, please nag me if I forget.

@DmitryOlshansky
Copy link
Member

Seems like all is in order.
https://gist.github.com/DmitryOlshansky/7ce9394ccc5bf27359da

@DmitryOlshansky
Copy link
Member

Auto-merge toggled on

DmitryOlshansky added a commit that referenced this pull request Sep 10, 2014
Issue 13419 - Remove comma expression in std.uni
@DmitryOlshansky DmitryOlshansky merged commit a965ffb into dlang:master Sep 10, 2014
@schuetzm schuetzm deleted the ketmar-kill-the-commas branch September 11, 2014 09:05
@quickfur
Copy link
Member

Stumbled across the bugzilla issue related to the if/else branch inlining issue today; thought I should log it here (i dunno, for posterity, or perhaps somebody will take a look at it): https://issues.dlang.org/show_bug.cgi?id=7625

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants