{"action":"closed","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/14177","repository_url":"https://api.github.com/repos/dotnet/coreclr","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/14177/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/14177/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/14177/events","html_url":"https://github.com/dotnet/coreclr/issues/14177","id":260425544,"node_id":"MDU6SXNzdWUyNjA0MjU1NDQ=","number":14177,"title":"Unreachable try/catch not elided by JIT","user":{"login":"stephentoub","id":2642209,"node_id":"MDQ6VXNlcjI2NDIyMDk=","avatar_url":"https://avatars0.githubusercontent.com/u/2642209?v=4","gravatar_id":"","url":"https://api.github.com/users/stephentoub","html_url":"https://github.com/stephentoub","followers_url":"https://api.github.com/users/stephentoub/followers","following_url":"https://api.github.com/users/stephentoub/following{/other_user}","gists_url":"https://api.github.com/users/stephentoub/gists{/gist_id}","starred_url":"https://api.github.com/users/stephentoub/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephentoub/subscriptions","organizations_url":"https://api.github.com/users/stephentoub/orgs","repos_url":"https://api.github.com/users/stephentoub/repos","events_url":"https://api.github.com/users/stephentoub/events{/privacy}","received_events_url":"https://api.github.com/users/stephentoub/received_events","type":"User","site_admin":false},"labels":[{"id":196940911,"node_id":"MDU6TGFiZWwxOTY5NDA5MTE=","url":"https://api.github.com/repos/dotnet/coreclr/labels/area-CodeGen","name":"area-CodeGen","color":"d4c5f9","default":false},{"id":172143005,"node_id":"MDU6TGFiZWwxNzIxNDMwMDU=","url":"https://api.github.com/repos/dotnet/coreclr/labels/enhancement","name":"enhancement","color":"1d76db","default":true},{"id":190283555,"node_id":"MDU6TGFiZWwxOTAyODM1NTU=","url":"https://api.github.com/repos/dotnet/coreclr/labels/optimization","name":"optimization","color":"0052cc","default":false},{"id":191917125,"node_id":"MDU6TGFiZWwxOTE5MTcxMjU=","url":"https://api.github.com/repos/dotnet/coreclr/labels/tenet-performance","name":"tenet-performance","color":"c2e0c6","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/dotnet/coreclr/milestones/5","html_url":"https://github.com/dotnet/coreclr/milestone/5","labels_url":"https://api.github.com/repos/dotnet/coreclr/milestones/5/labels","id":1328081,"node_id":"MDk6TWlsZXN0b25lMTMyODA4MQ==","number":5,"title":"Future","description":"Milestone tracking issues not triaged to a planned release. Work in this milestone may happen, or may not: it is not committed.","creator":{"login":"joshfree","id":1302850,"node_id":"MDQ6VXNlcjEzMDI4NTA=","avatar_url":"https://avatars1.githubusercontent.com/u/1302850?v=4","gravatar_id":"","url":"https://api.github.com/users/joshfree","html_url":"https://github.com/joshfree","followers_url":"https://api.github.com/users/joshfree/followers","following_url":"https://api.github.com/users/joshfree/following{/other_user}","gists_url":"https://api.github.com/users/joshfree/gists{/gist_id}","starred_url":"https://api.github.com/users/joshfree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshfree/subscriptions","organizations_url":"https://api.github.com/users/joshfree/orgs","repos_url":"https://api.github.com/users/joshfree/repos","events_url":"https://api.github.com/users/joshfree/events{/privacy}","received_events_url":"https://api.github.com/users/joshfree/received_events","type":"User","site_admin":false},"open_issues":1366,"closed_issues":1345,"state":"open","created_at":"2015-09-29T00:26:07Z","updated_at":"2018-09-20T12:33:25Z","due_on":null,"closed_at":null},"comments":4,"created_at":"2017-09-25T21:47:25Z","updated_at":"2018-09-20T12:33:24Z","closed_at":"2018-09-20T12:33:24Z","author_association":"MEMBER","body":"Consider:\r\n```C#\r\nusing System;\r\n\r\nclass Program\r\n{\r\n    static void Main()\r\n    {\r\n        Foo(42);\r\n    }\r\n\r\n    static void Foo<T>(T input)\r\n    {\r\n        if (typeof(T) == typeof(int))\r\n        {\r\n            Console.WriteLine(((int)(object)input).ToString());\r\n        }\r\n        else\r\n        {\r\n            try { Console.WriteLine(\"else\"); }\r\n            catch (Exception e) { Console.WriteLine(e); }\r\n        }\r\n    }\r\n}\r\n```\r\nThe JitDisasm for Foo is:\r\n```\r\nG_M46115_IG01:\r\n       55                   push     rbp\r\n       56                   push     rsi\r\n       4883EC28             sub      rsp, 40\r\n       488D6C2430           lea      rbp, [rsp+30H]\r\n       488965F0             mov      qword ptr [rbp-10H], rsp\r\n       8BF1                 mov      esi, ecx\r\n\r\nG_M46115_IG02:\r\n       E8AA5BFDFF           call     System.Globalization.NumberFormatInfo:get_CurrentInfo():ref\r\n       4C8BC0               mov      r8, rax\r\n       8BCE                 mov      ecx, esi\r\n       33D2                 xor      rdx, rdx\r\n       E8AE209D5F           call     System.Number:FormatInt32(int,ref,ref):ref\r\n       488BC8               mov      rcx, rax\r\n       E82EFCFFFF           call     System.Console:WriteLine(ref)\r\n       90                   nop\r\n\r\nG_M46115_IG03:\r\n       488D65F8             lea      rsp, [rbp-08H]\r\n       5E                   pop      rsi\r\n       5D                   pop      rbp\r\n       C3                   ret\r\n\r\nG_M46115_IG04:\r\n       CC                   int3\r\n\r\nG_M46115_IG05:\r\n       488D65F8             lea      rsp, [rbp-08H]\r\n       5E                   pop      rsi\r\n       5D                   pop      rbp\r\n       C3                   ret\r\n\r\nG_M46115_IG06:\r\n       55                   push     rbp\r\n       56                   push     rsi\r\n       4883EC28             sub      rsp, 40\r\n       488B6920             mov      rbp, qword ptr [rcx+32]\r\n       48896C2420           mov      qword ptr [rsp+20H], rbp\r\n       488D6D30             lea      rbp, [rbp+30H]\r\n\r\nG_M46115_IG07:\r\n       488BCA               mov      rcx, rdx\r\n       E8FBFBFFFF           call     System.Console:WriteLine(ref)\r\n       488D05D7FFFFFF       lea      rax, G_M46115_IG05\r\n\r\nG_M46115_IG08:\r\n       4883C428             add      rsp, 40\r\n       5E                   pop      rsi\r\n       5D                   pop      rbp\r\n       C3                   ret\r\n```\r\nbut if I remove the try/catch and just leave the Console.WriteLine from the try block:\r\n```C#\r\nusing System;\r\n\r\nclass Program\r\n{\r\n    static void Main()\r\n    {\r\n        Foo(42);\r\n    }\r\n\r\n    static void Foo<T>(T input)\r\n    {\r\n        if (typeof(T) == typeof(int))\r\n        {\r\n            Console.WriteLine(((int)(object)input).ToString());\r\n        }\r\n        else\r\n        {\r\n            Console.WriteLine(\"else\");\r\n        }\r\n    }\r\n}\r\n```\r\nthe else is removed as expected:\r\n```\r\nG_M46115_IG01:\r\n       56                   push     rsi\r\n       4883EC20             sub      rsp, 32\r\n       8BF1                 mov      esi, ecx\r\n\r\nG_M46115_IG02:\r\n       E8B45BFDFF           call     System.Globalization.NumberFormatInfo:get_CurrentInfo():ref\r\n       4C8BC0               mov      r8, rax\r\n       8BCE                 mov      ecx, esi\r\n       33D2                 xor      rdx, rdx\r\n       E8B820A05F           call     System.Number:FormatInt32(int,ref,ref):ref\r\n       488BC8               mov      rcx, rax\r\n       E838FCFFFF           call     System.Console:WriteLine(ref)\r\n       90                   nop\r\n\r\nG_M46115_IG03:\r\n       4883C420             add      rsp, 32\r\n       5E                   pop      rsi\r\n       C3                   ret\r\n```\r\nThis is also impacting the ability for Foo to be inlined, i.e. even with AggressiveInlining it won't be inlined if the try/catch exists in the else branch.\r\n\r\ncc: @AndyAyersMS \r\n\r\ncategory:cq\r\ntheme:flowgraph\r\nskill-level:intermediate\r\ncost:small"}}
{"actor":{"display_login":"stephentoub"}}