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

missed optimization with "complex" condition #1147

Open
1-Olivier opened this issue Apr 11, 2020 · 3 comments
Open

missed optimization with "complex" condition #1147

1-Olivier opened this issue Apr 11, 2020 · 3 comments

Comments

@1-Olivier
Copy link

This is similar to #1146 but likely has a different root cause. Consider this shader:

vector foo(float x, string a)
{
    vector result = 0;
    if( x >= -1 && a != "" )
    {
        result = 1;
    }
    return result;
}

surface simple(string s = "")
{
    P += foo(u, s);
}

Once again, testshade --debug simple.oso yields:

Globals written: (1)  P

Making the condition simpler:

vector foo(float x, string a)
{
    vector result = 0;
    if( a != "" )
    {
        result = 1;
    }
    return result;
}

is enough to get proper optimization:

Globals written: (0)

As that second condition can clearly be proven false, the first one should be easy to prove false also. So I would expect it to be optimized the same way.

Versions

  • OSL branch/version: 1.10.9 (testshade output above) / 3d0a284 (where I originally found the issue in a larger network)
  • OS: linux
  • LLVM version: 9.0.1 / 6.0.0
@1-Olivier
Copy link
Author

It gets more interesting: if I swap the condition around, to if( a != "" && x >= -1 ), the optimizer is able to figure it out.

@1-Olivier
Copy link
Author

More interesting trivia: swapping the condition to fix the optimization made a scene with some particularly ugly shader networks render 2.75 times faster.

@lgritz
Copy link
Collaborator

lgritz commented Apr 13, 2020

I will investigate

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

No branches or pull requests

2 participants