{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/48012","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/48012/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/48012/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/48012/events","html_url":"https://github.com/rust-lang/rust/pull/48012","id":294302100,"number":48012,"title":"Override try_[r]fold for RangeInclusive","user":{"login":"scottmcm","id":18526288,"avatar_url":"https://avatars2.githubusercontent.com/u/18526288?v=4","gravatar_id":"","url":"https://api.github.com/users/scottmcm","html_url":"https://github.com/scottmcm","followers_url":"https://api.github.com/users/scottmcm/followers","following_url":"https://api.github.com/users/scottmcm/following{/other_user}","gists_url":"https://api.github.com/users/scottmcm/gists{/gist_id}","starred_url":"https://api.github.com/users/scottmcm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scottmcm/subscriptions","organizations_url":"https://api.github.com/users/scottmcm/orgs","repos_url":"https://api.github.com/users/scottmcm/repos","events_url":"https://api.github.com/users/scottmcm/events{/privacy}","received_events_url":"https://api.github.com/users/scottmcm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars1.githubusercontent.com/u/64996?v=4","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false},"assignees":[{"login":"alexcrichton","id":64996,"avatar_url":"https://avatars1.githubusercontent.com/u/64996?v=4","gravatar_id":"","url":"https://api.github.com/users/alexcrichton","html_url":"https://github.com/alexcrichton","followers_url":"https://api.github.com/users/alexcrichton/followers","following_url":"https://api.github.com/users/alexcrichton/following{/other_user}","gists_url":"https://api.github.com/users/alexcrichton/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcrichton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcrichton/subscriptions","organizations_url":"https://api.github.com/users/alexcrichton/orgs","repos_url":"https://api.github.com/users/alexcrichton/repos","events_url":"https://api.github.com/users/alexcrichton/events{/privacy}","received_events_url":"https://api.github.com/users/alexcrichton/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2018-02-05T07:58:35Z","updated_at":"2018-02-05T07:58:47Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/48012","html_url":"https://github.com/rust-lang/rust/pull/48012","diff_url":"https://github.com/rust-lang/rust/pull/48012.diff","patch_url":"https://github.com/rust-lang/rust/pull/48012.patch"},"body":"Because the last item needs special handling, it seems that LLVM has trouble canonicalizing the loops in external iteration.  With the override, it becomes obvious that the start==end case exits the loop (as opposed to the one *after* that exiting the loop in external iteration).\r\n\r\nDemo adapted from https://github.com/rust-lang/rust/issues/45222\r\n```rust\r\n#[no_mangle]\r\npub fn foo3r(n: u64) -> u64 {\r\n    let mut count = 0;\r\n    (0..n).for_each(|_| {\r\n        (0 ..= n).rev().for_each(|j| {\r\n            count += j;\r\n        })\r\n    });\r\n    count\r\n}\r\n```\r\n\r\n\r\n<details>\r\n <summary>Current nightly ASM, 100 lines (https://play.rust-lang.org/?gist=f5674c702c6e2045c3aab5d03763e5f6&version=nightly&mode=release)</summary>\r\n\r\n```asm\r\nfoo3r:\r\n\tpushq\t%rbx\r\n.Lcfi0:\r\n.Lcfi1:\r\n\ttestq\t%rdi, %rdi\r\n\tje\t.LBB0_1\r\n\ttestb\t$1, %dil\r\n\tjne\t.LBB0_4\r\n\txorl\t%eax, %eax\r\n\txorl\t%r8d, %r8d\r\n\tcmpq\t$1, %rdi\r\n\tjne\t.LBB0_11\r\n\tjmp\t.LBB0_23\r\n.LBB0_1:\r\n\txorl\t%eax, %eax\r\n\tpopq\t%rbx\r\n\tretq\r\n.LBB0_4:\r\n\txorl\t%r8d, %r8d\r\n\tmovq\t$-1, %r9\r\n\txorl\t%eax, %eax\r\n\tmovq\t%rdi, %r11\r\n\txorl\t%r10d, %r10d\r\n\tjmp\t.LBB0_5\r\n.LBB0_8:\r\n\taddq\t%r11, %rax\r\n\tmovq\t%rsi, %r11\r\n\tmovq\t%rdx, %r10\r\n.LBB0_5:\r\n\tcmpq\t%r11, %r10\r\n\tmovl\t$1, %ecx\r\n\tcmovbq\t%r9, %rcx\r\n\tcmoveq\t%r8, %rcx\r\n\ttestq\t%rcx, %rcx\r\n\tmovl\t$0, %esi\r\n\tmovl\t$1, %edx\r\n\tje\t.LBB0_8\r\n\tcmpq\t$-1, %rcx\r\n\tjne\t.LBB0_9\r\n\tleaq\t-1(%r11), %rsi\r\n\tmovq\t%r10, %rdx\r\n\tjmp\t.LBB0_8\r\n.LBB0_9:\r\n\tmovl\t$1, %r8d\r\n\tcmpq\t$1, %rdi\r\n\tje\t.LBB0_23\r\n.LBB0_11:\r\n\txorl\t%r9d, %r9d\r\n\tmovq\t$-1, %r10\r\n.LBB0_12:\r\n\tmovq\t%rdi, %rsi\r\n\txorl\t%r11d, %r11d\r\n\tjmp\t.LBB0_13\r\n.LBB0_16:\r\n\taddq\t%rsi, %rax\r\n\tmovq\t%rcx, %rsi\r\n\tmovq\t%rbx, %r11\r\n.LBB0_13:\r\n\tcmpq\t%rsi, %r11\r\n\tmovl\t$1, %edx\r\n\tcmovbq\t%r10, %rdx\r\n\tcmoveq\t%r9, %rdx\r\n\ttestq\t%rdx, %rdx\r\n\tmovl\t$0, %ecx\r\n\tmovl\t$1, %ebx\r\n\tje\t.LBB0_16\r\n\tcmpq\t$-1, %rdx\r\n\tjne\t.LBB0_17\r\n\tleaq\t-1(%rsi), %rcx\r\n\tmovq\t%r11, %rbx\r\n\tjmp\t.LBB0_16\r\n.LBB0_17:\r\n\tmovq\t%rdi, %rcx\r\n\txorl\t%r11d, %r11d\r\n\tjmp\t.LBB0_18\r\n.LBB0_21:\r\n\taddq\t%rcx, %rax\r\n\tmovq\t%rsi, %rcx\r\n\tmovq\t%rbx, %r11\r\n.LBB0_18:\r\n\tcmpq\t%rcx, %r11\r\n\tmovl\t$1, %edx\r\n\tcmovbq\t%r10, %rdx\r\n\tcmoveq\t%r9, %rdx\r\n\ttestq\t%rdx, %rdx\r\n\tmovl\t$0, %esi\r\n\tmovl\t$1, %ebx\r\n\tje\t.LBB0_21\r\n\tcmpq\t$-1, %rdx\r\n\tjne\t.LBB0_22\r\n\tleaq\t-1(%rcx), %rsi\r\n\tmovq\t%r11, %rbx\r\n\tjmp\t.LBB0_21\r\n.LBB0_22:\r\n\taddq\t$2, %r8\r\n\tcmpq\t%rdi, %r8\r\n\tjne\t.LBB0_12\r\n.LBB0_23:\r\n\tpopq\t%rbx\r\n\tretq\r\n.Lfunc_end0:\r\n```\r\n</details><br>\r\n\r\nWith this PR:\r\n```asm\r\nfoo3r:\r\n\ttest\trcx, rcx\r\n\tje\t.LBB3_1\r\n\tlea\tr8, [rcx - 1]\r\n\tlea\trdx, [rcx - 2]\r\n\tmov\trax, r8\r\n\tmul\trdx\r\n\tshld\trdx, rax, 63\r\n\timul\tr8, r8\r\n\tadd\tr8, rcx\r\n\tsub\tr8, rdx\r\n\timul\tr8, rcx\r\n\tmov\trax, r8\r\n\tret\r\n.LBB3_1:\r\n\txor\tr8d, r8d\r\n\tmov\trax, r8\r\n\tret\r\n```"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/363007397","html_url":"https://github.com/rust-lang/rust/pull/48012#issuecomment-363007397","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/48012","id":363007397,"user":{"login":"rust-highfive","id":7378925,"avatar_url":"https://avatars3.githubusercontent.com/u/7378925?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-highfive","html_url":"https://github.com/rust-highfive","followers_url":"https://api.github.com/users/rust-highfive/followers","following_url":"https://api.github.com/users/rust-highfive/following{/other_user}","gists_url":"https://api.github.com/users/rust-highfive/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-highfive/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-highfive/subscriptions","organizations_url":"https://api.github.com/users/rust-highfive/orgs","repos_url":"https://api.github.com/users/rust-highfive/repos","events_url":"https://api.github.com/users/rust-highfive/events{/privacy}","received_events_url":"https://api.github.com/users/rust-highfive/received_events","type":"User","site_admin":false},"created_at":"2018-02-05T07:58:47Z","updated_at":"2018-02-05T07:58:47Z","author_association":"COLLABORATOR","body":"r? @alexcrichton\n\n(rust_highfive has picked a reviewer for you, use r? to override)"}}
{"actor":{"display_login":"rust-highfive"}}