{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/54868","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/54868/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/54868/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/54868/events","html_url":"https://github.com/rust-lang/rust/issues/54868","id":367460273,"node_id":"MDU6SXNzdWUzNjc0NjAyNzM=","number":54868,"title":"Division by nonzero","user":{"login":"leonardo-m","id":22328461,"node_id":"MDQ6VXNlcjIyMzI4NDYx","avatar_url":"https://avatars0.githubusercontent.com/u/22328461?v=4","gravatar_id":"","url":"https://api.github.com/users/leonardo-m","html_url":"https://github.com/leonardo-m","followers_url":"https://api.github.com/users/leonardo-m/followers","following_url":"https://api.github.com/users/leonardo-m/following{/other_user}","gists_url":"https://api.github.com/users/leonardo-m/gists{/gist_id}","starred_url":"https://api.github.com/users/leonardo-m/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leonardo-m/subscriptions","organizations_url":"https://api.github.com/users/leonardo-m/orgs","repos_url":"https://api.github.com/users/leonardo-m/repos","events_url":"https://api.github.com/users/leonardo-m/events{/privacy}","received_events_url":"https://api.github.com/users/leonardo-m/received_events","type":"User","site_admin":false},"labels":[{"id":113376,"node_id":"MDU6TGFiZWwxMTMzNzY=","url":"https://api.github.com/repos/rust-lang/rust/labels/I-slow","name":"I-slow","color":"e10c02","default":false},{"id":211668100,"node_id":"MDU6TGFiZWwyMTE2NjgxMDA=","url":"https://api.github.com/repos/rust-lang/rust/labels/T-compiler","name":"T-compiler","color":"bfd4f2","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-06T14:08:01Z","updated_at":"2018-10-11T17:19:17Z","closed_at":null,"author_association":"NONE","body":"Rustc seems unable to use the fact that NonZeroU64 isn't zero:\r\n\r\n```\r\nuse std::num::NonZeroU64;\r\n\r\n#[inline(never)]\r\nfn foo(x: u64, y: NonZeroU64) -> u64 {\r\n    x / y.get()\r\n}\r\n```\r\n\r\nGives the asm (with -O):\r\n\r\n```\r\n_ZN4test3foo17h70af812d10d8d714E:\r\n    subq    $40, %rsp\r\n    testq   %rdx, %rdx\r\n    je  .LBB9_2\r\n    movq    %rdx, %r8\r\n    xorl    %edx, %edx\r\n    movq    %rcx, %rax\r\n    divq    %r8\r\n    addq    $40, %rsp\r\n    retq\r\n.LBB9_2:\r\n    leaq    .L__unnamed_6(%rip), %rcx\r\n    callq   _ZN4core9panicking5panic17h6a1e45881f6169d7E\r\n    ud2\r\n```\r\n\r\nAdding an assume() solves the problem:\r\n\r\n```\r\n#![feature(core_intrinsics)]\r\nuse std::num::NonZeroU64;\r\nuse std::intrinsics::assume;\r\n\r\n#[inline(never)]\r\nfn foo2(x: u64, y: NonZeroU64) -> u64 {\r\n    let y2 = y.get();\r\n    unsafe { assume(y2 != 0); }\r\n    x / y2\r\n}\r\n\r\n\r\n_ZN5test24foo217hf17fb494647eabb3E:\r\n    movq    %rdx, %r8\r\n    xorl    %edx, %edx\r\n    movq    %rcx, %rax\r\n    divq    %r8\r\n    retq\r\n```\r\n\r\nPerhaps such assume() should be added at the end of NonZeroU64::get()?"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/429042464","html_url":"https://github.com/rust-lang/rust/issues/54868#issuecomment-429042464","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/54868","id":429042464,"node_id":"MDEyOklzc3VlQ29tbWVudDQyOTA0MjQ2NA==","user":{"login":"scottmcm","id":18526288,"node_id":"MDQ6VXNlcjE4NTI2Mjg4","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},"created_at":"2018-10-11T17:19:17Z","updated_at":"2018-10-11T17:19:17Z","author_association":"MEMBER","body":"Dup of https://github.com/rust-lang/rust/issues/49572?"}}
{"actor":{"display_login":"scottmcm"}}