{"action":"opened","issue":{"url":"https://api.github.com/repos/golang/go/issues/15844","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/15844/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/15844/comments","events_url":"https://api.github.com/repos/golang/go/issues/15844/events","html_url":"https://github.com/golang/go/issues/15844","id":156897407,"number":15844,"title":"cmd/compile: recognize and optimize \"in range\" booleans","user":{"login":"josharian","id":67496,"avatar_url":"https://avatars.githubusercontent.com/u/67496?v=3","gravatar_id":"","url":"https://api.github.com/users/josharian","html_url":"https://github.com/josharian","followers_url":"https://api.github.com/users/josharian/followers","following_url":"https://api.github.com/users/josharian/following{/other_user}","gists_url":"https://api.github.com/users/josharian/gists{/gist_id}","starred_url":"https://api.github.com/users/josharian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josharian/subscriptions","organizations_url":"https://api.github.com/users/josharian/orgs","repos_url":"https://api.github.com/users/josharian/repos","events_url":"https://api.github.com/users/josharian/events{/privacy}","received_events_url":"https://api.github.com/users/josharian/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/golang/go/labels/Performance","name":"Performance","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/38","html_url":"https://github.com/golang/go/milestones/Go1.8","labels_url":"https://api.github.com/repos/golang/go/milestones/38/labels","id":1709363,"number":38,"title":"Go1.8","description":"","creator":{"login":"griesemer","id":8528975,"avatar_url":"https://avatars.githubusercontent.com/u/8528975?v=3","gravatar_id":"","url":"https://api.github.com/users/griesemer","html_url":"https://github.com/griesemer","followers_url":"https://api.github.com/users/griesemer/followers","following_url":"https://api.github.com/users/griesemer/following{/other_user}","gists_url":"https://api.github.com/users/griesemer/gists{/gist_id}","starred_url":"https://api.github.com/users/griesemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/griesemer/subscriptions","organizations_url":"https://api.github.com/users/griesemer/orgs","repos_url":"https://api.github.com/users/griesemer/repos","events_url":"https://api.github.com/users/griesemer/events{/privacy}","received_events_url":"https://api.github.com/users/griesemer/received_events","type":"User","site_admin":false},"open_issues":229,"closed_issues":13,"state":"open","created_at":"2016-04-15T16:30:23Z","updated_at":"2016-05-26T03:43:39Z","due_on":"2017-02-01T08:00:00Z","closed_at":null},"comments":0,"created_at":"2016-05-26T03:43:39Z","updated_at":"2016-05-26T03:43:39Z","closed_at":null,"body":"```go\r\npackage p\r\n\r\nfunc inrange(x int) bool {\r\n\treturn 5 <= x && x < 10\r\n}\r\n\r\nfunc inrange2(x int) bool {\r\n\treturn uint(x-5) < 5\r\n}\r\n```\r\n\r\nThese two functions are equivalent, but the second is more efficient (it trades a subtraction for a compare-and-branch). We do this already for index-in-bounds checks. We should generally recognize integer-in-range patterns and convert them.\r\n\r\nWe should probably do this in the SSA backend, since it'll be more general and powerful there than a limited front-end rewrite like rotation recognition. (I'm open to being convinced otherwise, though.)\r\n\r\nThis will be helpful for #15780. It'll also help a bit with a hot line in scanobject (`arena_start <= obj && obj < arena_used`).\r\n\r\n/cc @brtzsnr @randall77 \r\n"}}
{"actor":{"display_login":"josharian"}}