{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/17370","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/17370/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/17370/comments","events_url":"https://api.github.com/repos/golang/go/issues/17370/events","html_url":"https://github.com/golang/go/issues/17370","id":181542127,"number":17370,"title":"cmd/compile: eliminate more bounds checks","user":{"login":"carl-mastrangelo","id":8943572,"avatar_url":"https://avatars.githubusercontent.com/u/8943572?v=3","gravatar_id":"","url":"https://api.github.com/users/carl-mastrangelo","html_url":"https://github.com/carl-mastrangelo","followers_url":"https://api.github.com/users/carl-mastrangelo/followers","following_url":"https://api.github.com/users/carl-mastrangelo/following{/other_user}","gists_url":"https://api.github.com/users/carl-mastrangelo/gists{/gist_id}","starred_url":"https://api.github.com/users/carl-mastrangelo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carl-mastrangelo/subscriptions","organizations_url":"https://api.github.com/users/carl-mastrangelo/orgs","repos_url":"https://api.github.com/users/carl-mastrangelo/repos","events_url":"https://api.github.com/users/carl-mastrangelo/events{/privacy}","received_events_url":"https://api.github.com/users/carl-mastrangelo/received_events","type":"User","site_admin":false},"labels":[{"id":150880191,"url":"https://api.github.com/repos/golang/go/labels/Performance","name":"Performance","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/golang/go/milestones/6","html_url":"https://github.com/golang/go/milestone/6","labels_url":"https://api.github.com/repos/golang/go/milestones/6/labels","id":1055141,"number":6,"title":"Unplanned","description":"No plan to fix in any specific release.\r\n","creator":{"login":"rsc","id":104030,"avatar_url":"https://avatars.githubusercontent.com/u/104030?v=3","gravatar_id":"","url":"https://api.github.com/users/rsc","html_url":"https://github.com/rsc","followers_url":"https://api.github.com/users/rsc/followers","following_url":"https://api.github.com/users/rsc/following{/other_user}","gists_url":"https://api.github.com/users/rsc/gists{/gist_id}","starred_url":"https://api.github.com/users/rsc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsc/subscriptions","organizations_url":"https://api.github.com/users/rsc/orgs","repos_url":"https://api.github.com/users/rsc/repos","events_url":"https://api.github.com/users/rsc/events{/privacy}","received_events_url":"https://api.github.com/users/rsc/received_events","type":"User","site_admin":false},"open_issues":1201,"closed_issues":605,"state":"open","created_at":"2015-04-06T20:47:19Z","updated_at":"2016-12-21T06:40:05Z","due_on":"2099-12-31T08:00:00Z","closed_at":null},"comments":7,"created_at":"2016-10-06T22:32:21Z","updated_at":"2016-12-21T11:00:05Z","closed_at":null,"body":"### What version of Go are you using (`go version`)?\n\ngo version devel +fe77c5b Mon Oct 3 18:26:43 2016 +0000 linux/amd64\n### What operating system and processor architecture are you using (`go env`)?\n### What did you do?\n\nhttps://play.golang.org/p/KvKjpisUOl\n### What did you expect to see?\n\nbounds checks eliminated from assembly\n### What did you see instead?\n\n```\nTEXT main.blah(SB) /home/notcarl/Desktop/bce.go\n    bce.go:9    0x401000    64488b0c25f8ffffff  FS MOVQ FS:0xfffffff8, CX       \n    bce.go:9    0x401009    483b6110        CMPQ 0x10(CX), SP           \n    bce.go:9    0x40100d    0f864b010000        JBE 0x40115e                \n    bce.go:9    0x401013    4883ec38        SUBQ $0x38, SP              \n    bce.go:9    0x401017    48896c2430      MOVQ BP, 0x30(SP)           \n    bce.go:9    0x40101c    488d6c2430      LEAQ 0x30(SP), BP           \n    bce.go:10   0x401021    488b0570620900      MOVQ 0x96270(IP), AX            \n    bce.go:10   0x401028    488b0d61620900      MOVQ 0x96261(IP), CX            \n    bce.go:12   0x40102f    488b1502080b00      MOVQ 0xb0802(IP), DX            \n    bce.go:12   0x401036    4889c3          MOVQ AX, BX             \n    bce.go:12   0x401039    4829d0          SUBQ DX, AX             \n    bce.go:12   0x40103c    4883f804        CMPQ $0x4, AX               \n    bce.go:12   0x401040    0f8ccf000000        JL 0x401115             \n    bce.go:15   0x401046    488d4203        LEAQ 0x3(DX), AX            \n    bce.go:15   0x40104a    4839d8          CMPQ BX, AX             \n    bce.go:15   0x40104d    0f83bb000000        JAE 0x40110e                \n    bce.go:16   0x401053    4839da          CMPQ BX, DX             \n    bce.go:16   0x401056    0f83ab000000        JAE 0x401107                \n    bce.go:16   0x40105c    0fb60c11        MOVZX 0(CX)(DX*1), CX           \n    bce.go:16   0x401060    80f980          CMPL $0x80, CL              \n    bce.go:16   0x401063    760a            JBE 0x40106f                \n    bce.go:34   0x401065    488b6c2430      MOVQ 0x30(SP), BP           \n    bce.go:34   0x40106a    4883c438        ADDQ $0x38, SP              \n    bce.go:34   0x40106e    c3          RET                 \n    bce.go:19   0x40106f    488d4a01        LEAQ 0x1(DX), CX            \n    bce.go:19   0x401073    48890dbe070b00      MOVQ CX, 0xb07be(IP)            \n    bce.go:20   0x40107a    488b1d17620900      MOVQ 0x96217(IP), BX            \n    bce.go:20   0x401081    488b3508620900      MOVQ 0x96208(IP), SI            \n    bce.go:20   0x401088    4839d9          CMPQ BX, CX             \n    bce.go:20   0x40108b    7373            JAE 0x401100                \n    bce.go:20   0x40108d    0fb64c1601      MOVZX 0x1(SI)(DX*1), CX         \n    bce.go:20   0x401092    80f980          CMPL $0x80, CL              \n    bce.go:20   0x401095    77ce            JA 0x401065             \n    bce.go:23   0x401097    488d4a02        LEAQ 0x2(DX), CX            \n    bce.go:23   0x40109b    48890d96070b00      MOVQ CX, 0xb0796(IP)            \n    bce.go:24   0x4010a2    488b1def610900      MOVQ 0x961ef(IP), BX            \n    bce.go:24   0x4010a9    488b35e0610900      MOVQ 0x961e0(IP), SI            \n    bce.go:24   0x4010b0    4839d9          CMPQ BX, CX             \n    bce.go:24   0x4010b3    7344            JAE 0x4010f9                \n    bce.go:24   0x4010b5    0fb64c1602      MOVZX 0x2(SI)(DX*1), CX         \n    bce.go:24   0x4010ba    80f980          CMPL $0x80, CL              \n    bce.go:24   0x4010bd    77a6            JA 0x401065             \n    bce.go:27   0x4010bf    48890572070b00      MOVQ AX, 0xb0772(IP)            \n    bce.go:28   0x4010c6    488b0dcb610900      MOVQ 0x961cb(IP), CX            \n    bce.go:28   0x4010cd    488b1dbc610900      MOVQ 0x961bc(IP), BX            \n    bce.go:28   0x4010d4    4839c8          CMPQ CX, AX             \n    bce.go:28   0x4010d7    7319            JAE 0x4010f2                \n    bce.go:28   0x4010d9    0fb6441303      MOVZX 0x3(BX)(DX*1), AX         \n    bce.go:28   0x4010de    3c80            CMPL $0x80, AL              \n    bce.go:28   0x4010e0    7783            JA 0x401065             \n    bce.go:31   0x4010e2    488d4204        LEAQ 0x4(DX), AX            \n    bce.go:31   0x4010e6    4889054b070b00      MOVQ AX, 0xb074b(IP)            \n    bce.go:34   0x4010ed    e973ffffff      JMP 0x401065                \n    bce.go:28   0x4010f2    e8c9ed0100      CALL runtime.panicindex(SB)     \n    bce.go:28   0x4010f7    0f0b            UD2                 \n    bce.go:24   0x4010f9    e8c2ed0100      CALL runtime.panicindex(SB)     \n    bce.go:24   0x4010fe    0f0b            UD2                 \n    bce.go:20   0x401100    e8bbed0100      CALL runtime.panicindex(SB)     \n    bce.go:20   0x401105    0f0b            UD2                 \n    bce.go:16   0x401107    e8b4ed0100      CALL runtime.panicindex(SB)     \n    bce.go:16   0x40110c    0f0b            UD2                 \n    bce.go:15   0x40110e    e8aded0100      CALL runtime.panicindex(SB)     \n    bce.go:15   0x401113    0f0b            UD2                 \n    bce.go:36   0x401115    488d05ad430600      LEAQ 0x643ad(IP), AX            \n    bce.go:36   0x40111c    4889442420      MOVQ AX, 0x20(SP)           \n    bce.go:36   0x401121    48c744242803000000  MOVQ $0x3, 0x28(SP)         \n    bce.go:36   0x40112a    488d056f380500      LEAQ 0x5386f(IP), AX            \n    bce.go:36   0x401131    48890424        MOVQ AX, 0(SP)              \n    bce.go:36   0x401135    488d442420      LEAQ 0x20(SP), AX           \n    bce.go:36   0x40113a    4889442408      MOVQ AX, 0x8(SP)            \n    bce.go:36   0x40113f    e81c770000      CALL runtime.convT2E(SB)        \n    bce.go:36   0x401144    488b442410      MOVQ 0x10(SP), AX           \n    bce.go:36   0x401149    488b4c2418      MOVQ 0x18(SP), CX           \n    bce.go:36   0x40114e    48890424        MOVQ AX, 0(SP)              \n    bce.go:36   0x401152    48894c2408      MOVQ CX, 0x8(SP)            \n    bce.go:36   0x401157    e8a4fd0100      CALL runtime.gopanic(SB)        \n    bce.go:36   0x40115c    0f0b            UD2                 \n    bce.go:9    0x40115e    e89d600400      CALL runtime.morestack_noctxt(SB)   \n    bce.go:9    0x401163    e998feffff      JMP main.blah(SB)           \n```\n\nI _think_ the chain of panicindex calls should be removed, since both the:\n\n```\n if l - i < 4 {\n    goto fail\n  }\n```\n\nand  `_ = buf[i+3]`  calls should make it clear that the subsequent accesses cannot possibly go out of bounds.  Sorry if this is noise and it's WAI.\n"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/268495189","html_url":"https://github.com/golang/go/issues/17370#issuecomment-268495189","issue_url":"https://api.github.com/repos/golang/go/issues/17370","id":268495189,"user":{"login":"willnewton","id":93721,"avatar_url":"https://avatars.githubusercontent.com/u/93721?v=3","gravatar_id":"","url":"https://api.github.com/users/willnewton","html_url":"https://github.com/willnewton","followers_url":"https://api.github.com/users/willnewton/followers","following_url":"https://api.github.com/users/willnewton/following{/other_user}","gists_url":"https://api.github.com/users/willnewton/gists{/gist_id}","starred_url":"https://api.github.com/users/willnewton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/willnewton/subscriptions","organizations_url":"https://api.github.com/users/willnewton/orgs","repos_url":"https://api.github.com/users/willnewton/repos","events_url":"https://api.github.com/users/willnewton/events{/privacy}","received_events_url":"https://api.github.com/users/willnewton/received_events","type":"User","site_admin":false},"created_at":"2016-12-21T11:00:05Z","updated_at":"2016-12-21T11:00:05Z","body":"With Go 1.7.4 this code produces bounds checks on all 4 stores in the loop.\r\n\r\n    func boundsCheck(s []int) {\r\n            n := len(s) / 4\r\n    \tfor i := 0; i < n; i++ {\r\n    \t    \ts[i] = i\r\n    \t\ts[i+1] = i \r\n    \t\ts[i+2] = i\r\n    \t\ts[i+3] = i\r\n    \t}\r\n    }\r\n\r\nIt seems like it should be possible to reorder the stores to eliminate 3 of the bounds checks:\r\n\r\n    func boundsCheck(s []int) {\r\n    \tn := len(s) / 4\r\n    \tfor i := 0; i < n; i++ {\r\n    \t\ts[i+3] = i\r\n    \t    \ts[i] = i\r\n    \t\ts[i+1] = i \r\n    \t\ts[i+2] = i\r\n    \t}\r\n    }\r\n\r\nHowever this results in 4 bounds checks as before.\r\n"}}
{"actor":{"display_login":"willnewton"}}