AcademySoftwareFoundation / AcademySoftwareFoundation/OpenShadingLanguage
missed optimization with "complex" condition
- Dominant language
- C++
- Stars
- 2.3k
- Forks
- 414
- Avg merge
- 3d 1h
- Merged PRs (30d)
- 10
Description
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) / 3d0a284e997367b5b63bf8ea16911391fa1fea85 (where I originally found the issue in a larger network)
* OS: linux
* LLVM version: 9.0.1 / 6.0.0
Contributor guide
Research direction
Reproduce the shader from the issue with `testshade --debug simple.oso`, comparing the complex condition with the simpler `a != ""` condition. Trace the optimization path responsible for proving the condition false, and confirm the fix makes the first case report `Globals written: (0)` as well.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100