dotnet/roslyn
Compiler should optimize common boolean return patterns
Offen
#34.726 geöffnet am 03.04.2019
Area-CompilersCode Gen Qualityhelp wanted
Repository-Metriken
- Stars
- (20.414 Sterne)
- PR-Merge-Metriken
- (Durchschn. Merge 6T 17h) (256 gemergte PRs in 30 T)
Beschreibung
Version Used: Rosyln master branch from 2nd April 2019
Steps to Reproduce: [Sharplab Demo]
- Have this code:
public bool Proper(object o) { return o is object; } - Also, have this unoptimized version
public bool ShouldBeOptimized(object o) { if (o is object) { return true; } return false; }
Expected Behavior:
Identical IL output, as they are semantically identical. This wouldn't be an issue but it does affect JIT output seemingly (JIT64 desktop, tested on Sharplab above) - it switches a setcc ; movzx pattern to a full branch, which is not ideal
Actual Behavior: IL generation has an additional branch and changes the generated JIT
It is a very minor issue but was recommended to create an issue for it