dotnet/roslyn

Compiler should optimize common boolean return patterns

开放

#34,726 创建于 2019年4月3日

 (9 条评论) (0 个反应) (0 位负责人)C# (4,257 个派生)batch import
Area-CompilersCode Gen Qualityhelp wanted

仓库指标

星标
 (20,414 个星标)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

Version Used: Rosyln master branch from 2nd April 2019

Steps to Reproduce: [Sharplab Demo]

  1. Have this code: public bool Proper(object o) { return o is object; }
  2. 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

贡献者指南