payload: {"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/runtime/issues/1378","repository_url":"https://api.github.com/repos/dotnet/runtime","labels_url":"https://api.github.com/repos/dotnet/runtime/issues/1378/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/runtime/issues/1378/comments","events_url":"https://api.github.com/repos/dotnet/runtime/issues/1378/events","html_url":"https://github.com/dotnet/runtime/pull/1378","id":546519610,"node_id":"MDExOlB1bGxSZXF1ZXN0MzYwMTgyNzc1","number":1378,"title":"JIT: Optimize \"constant_string\".Length","user":{"login":"EgorBo","id":523221,"node_id":"MDQ6VXNlcjUyMzIyMQ==","avatar_url":"https://avatars0.githubusercontent.com/u/523221?v=4","gravatar_id":"","url":"https://api.github.com/users/EgorBo","html_url":"https://github.com/EgorBo","followers_url":"https://api.github.com/users/EgorBo/followers","following_url":"https://api.github.com/users/EgorBo/following{/other_user}","gists_url":"https://api.github.com/users/EgorBo/gists{/gist_id}","starred_url":"https://api.github.com/users/EgorBo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EgorBo/subscriptions","organizations_url":"https://api.github.com/users/EgorBo/orgs","repos_url":"https://api.github.com/users/EgorBo/repos","events_url":"https://api.github.com/users/EgorBo/events{/privacy}","received_events_url":"https://api.github.com/users/EgorBo/received_events","type":"User","site_admin":false},"labels":[{"id":1675386352,"node_id":"MDU6TGFiZWwxNjc1Mzg2MzUy","url":"https://api.github.com/repos/dotnet/runtime/labels/area-CodeGen","name":"area-CodeGen","color":"d4c5f9","default":false,"description":null}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2020-01-07T21:34:49Z","updated_at":"2020-01-13T20:57:59Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/dotnet/runtime/pulls/1378","html_url":"https://github.com/dotnet/runtime/pull/1378","diff_url":"https://github.com/dotnet/runtime/pull/1378.diff","patch_url":"https://github.com/dotnet/runtime/pull/1378.patch"},"body":"Resurrects https://github.com/dotnet/coreclr/pull/26000\r\nExample (showcases why it's better to have this opt in JIT instead of Roslyn)\r\n```csharp\r\nbool Validate(string str)\r\n{\r\n    return str.Length > 0 && str.Length <= 100;\r\n}\r\n\r\nbool Test()\r\n{\r\n    return Validate(\"Hello\");  // Validate() will be inlined\r\n}\r\n```\r\nCurrent codegen for `Test` method:\r\n```asm\r\nG_M17178_IG01:\r\nG_M17178_IG02:\r\n       mov      rax, 0xD1FFAB1E\r\n       mov      rax, gword ptr [rax]\r\n       cmp      dword ptr [rax+8], 0\r\n       jle      SHORT G_M17178_IG04\r\nG_M17178_IG03:\r\n       cmp      dword ptr [rax+8], 100\r\n       setle    al\r\n       movzx    rax, al\r\n       jmp      SHORT G_M17178_IG05\r\nG_M17178_IG04:\r\n       xor      eax, eax\r\nG_M17178_IG05:\r\n       ret\r\n```\r\nNew codegen for `Test` method:\r\n```asm\r\nG_M17178_IG01:\r\nG_M17178_IG02:\r\n       mov      eax, 1     ; return true\r\nG_M17178_IG03:\r\n       ret  \r\n```\r\n\r\nThe optimization is now implemented in `importer.cpp` instead of `morph.cpp` (according to feedback). Also, didn't forget about crossgen2.\r\n\r\nJit-diff (see report with `--count 1000` [here](https://gist.github.com/EgorBo/f9e8a4cd7065b2cb045329fb0f3a7a18)):\r\n```\r\nTotal bytes of diff: -30053 (-0.07% of base)\r\n    diff is an improvement.\r\n\r\nTop file regressions by size (bytes):\r\n           6 : System.Private.Xml.Linq.dasm (0.00% of base)\r\n           4 : System.Diagnostics.TextWriterTraceListener.dasm (0.03% of base)\r\n\r\nTop file improvements by size (bytes):\r\n       -5917 : System.Private.CoreLib.dasm (-0.11% of base)\r\n       -4697 : System.Private.Xml.dasm (-0.13% of base)\r\n       -4370 : Microsoft.Diagnostics.Tracing.TraceEvent.dasm (-0.14% of base)\r\n       -3465 : Microsoft.CodeAnalysis.VisualBasic.dasm (-0.06% of base)\r\n       -1987 : System.Net.HttpListener.dasm (-0.84% of base)\r\n\r\n36 total files with size differences (34 improved, 2 regressed), 73 unchanged.\r\n\r\nTop method regressions by size (bytes):\r\n          70 ( 3.82% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.ActivityComputer:ResolveWellKnownSymbols():this\r\n          60 ( 4.63% of base) : Microsoft.CodeAnalysis.CSharp.dasm - Microsoft.CodeAnalysis.CSharp.Binder:BindIntegralMinValConstants(Microsoft.CodeAnalysis.CSharp.Syntax.PrefixUnaryExpressionSyntax,Microsoft.CodeAnalysis.CSharp.BoundExpression,Microsoft.CodeAnalysis.DiagnosticBag):Microsoft.CodeAnalysis.CSharp.BoundLiteral:this\r\n          20 ( 2.40% of base) : System.Private.Xml.dasm - System.Xml.HtmlEncodedRawTextWriter:WriteDocType(System.String,System.String,System.String,System.String):this\r\n          16 ( 2.02% of base) : System.Private.Xml.dasm - System.Xml.HtmlUtf8RawTextWriter:WriteDocType(System.String,System.String,System.String,System.String):this\r\n          16 ( 2.41% of base) : System.Private.Xml.dasm - System.Xml.XmlEncodedRawTextWriter:WriteDocType(System.String,System.String,System.String,System.String):this\r\n\r\nTop method improvements by size (bytes):\r\n        -829 (-29.31% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.Parsers.Kernel.MemoryProcessMemInfoTraceData:ToXml(System.Text.StringBuilder):System.Text.StringBuilder:this\r\n        -812 (-32.15% of base) : System.Net.Http.dasm - System.Net.Http.MultiProxy:TryParseProxyConfigPart(System.ReadOnlySpan`1[Char],bool,byref,byref):bool\r\n        -791 (-28.77% of base) : System.Private.Xml.dasm - System.Xml.XmlConvert:EncodeName(System.String,bool,bool):System.String\r\n        -784 (-17.38% of base) : System.Diagnostics.Process.dasm - System.Diagnostics.NtProcessManager:GetProcessInfos(System.Diagnostics.PerformanceCounterLib,int,int,System.ReadOnlySpan`1[Byte]):System.Diagnostics.ProcessInfo[]\r\n        -780 (-39.14% of base) : System.Private.CoreLib.dasm - System.Enum:ValueToHexString(System.Object):System.String\r\n\r\nTop method regressions by size (percentage):\r\n          60 ( 4.63% of base) : Microsoft.CodeAnalysis.CSharp.dasm - Microsoft.CodeAnalysis.CSharp.Binder:BindIntegralMinValConstants(Microsoft.CodeAnalysis.CSharp.Syntax.PrefixUnaryExpressionSyntax,Microsoft.CodeAnalysis.CSharp.BoundExpression,Microsoft.CodeAnalysis.DiagnosticBag):Microsoft.CodeAnalysis.CSharp.BoundLiteral:this\r\n          70 ( 3.82% of base) : Microsoft.Diagnostics.Tracing.TraceEvent.dasm - Microsoft.Diagnostics.Tracing.ActivityComputer:ResolveWellKnownSymbols():this\r\n          16 ( 2.41% of base) : System.Private.Xml.dasm - System.Xml.XmlEncodedRawTextWriter:WriteDocType(System.String,System.String,System.String,System.String):this\r\n          20 ( 2.40% of base) : System.Private.Xml.dasm - System.Xml.HtmlEncodedRawTextWriter:WriteDocType(System.String,System.String,System.String,System.String):this\r\n          16 ( 2.02% of base) : System.Private.Xml.dasm - System.Xml.HtmlUtf8RawTextWriter:WriteDocType(System.String,System.String,System.String,System.String):this\r\n\r\nTop method improvements by size (percentage):\r\n         -14 (-70.00% of base) : Microsoft.CodeAnalysis.dasm - Microsoft.Cci.PeWriter:get_SizeOfNameTable():int\r\n         -14 (-70.00% of base) : System.Reflection.Metadata.dasm - System.Reflection.PortableExecutable.ManagedTextSection:get_SizeOfNameTable():int\r\n         -85 (-49.71% of base) : System.Private.CoreLib.dasm - System.Char8:ToString():System.String:this\r\n         -86 (-47.51% of base) : System.Diagnostics.FileVersionInfo.dasm - System.Diagnostics.FileVersionInfo:ConvertTo8DigitHex(int):System.String\r\n         -92 (-45.10% of base) : System.Private.Xml.dasm - System.Xml.XmlTextEncoder:WriteCharEntityImpl(ushort):this\r\n```\r\nIn some rare cases this opt can brake bound check elimination over string literals but it doesn't work well even today (see https://github.com/dotnet/runtime/issues/1343)."},"comment":{"url":"https://api.github.com/repos/dotnet/runtime/issues/comments/573867038","html_url":"https://github.com/dotnet/runtime/pull/1378#issuecomment-573867038","issue_url":"https://api.github.com/repos/dotnet/runtime/issues/1378","id":573867038,"node_id":"MDEyOklzc3VlQ29tbWVudDU3Mzg2NzAzOA==","user":{"login":"EgorBo","id":523221,"node_id":"MDQ6VXNlcjUyMzIyMQ==","avatar_url":"https://avatars0.githubusercontent.com/u/523221?v=4","gravatar_id":"","url":"https://api.github.com/users/EgorBo","html_url":"https://github.com/EgorBo","followers_url":"https://api.github.com/users/EgorBo/followers","following_url":"https://api.github.com/users/EgorBo/following{/other_user}","gists_url":"https://api.github.com/users/EgorBo/gists{/gist_id}","starred_url":"https://api.github.com/users/EgorBo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EgorBo/subscriptions","organizations_url":"https://api.github.com/users/EgorBo/orgs","repos_url":"https://api.github.com/users/EgorBo/repos","events_url":"https://api.github.com/users/EgorBo/events{/privacy}","received_events_url":"https://api.github.com/users/EgorBo/received_events","type":"User","site_admin":false},"created_at":"2020-01-13T20:57:59Z","updated_at":"2020-01-13T20:57:59Z","author_association":"CONTRIBUTOR","body":"@AndyAyersMS jit-diff results with `COMPlus_JitNoInline=1`: \r\n```\r\nTotal bytes of diff: -804 (-0.00% of base)\r\n38 total methods with size differences (37 improved, 1 regressed), 262228 unchanged.\r\n```\r\nsee https://gist.github.com/EgorBo/4110b359ed109ea4ef198250aee3d3da\r\nThe only regression is this method: https://www.diffchecker.com/WyHZkCx8\r\n\r\nso it's -30053 (default) diff vs -804 (noinline)."}}
other: {"actor":{"display_login":"EgorBo"}}