Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: optimize range comparisons like 'A' <= c && c <= 'Z' #17372

Closed
rillig opened this issue Oct 6, 2016 · 3 comments
Closed

cmd/compile: optimize range comparisons like 'A' <= c && c <= 'Z' #17372

rillig opened this issue Oct 6, 2016 · 3 comments

Comments

@rillig
Copy link
Contributor

rillig commented Oct 6, 2016

What version of Go are you using (go version)?

go version go1.7.1 windows/amd64

What did you do?

https://play.golang.org/p/91drTKDs_m

What did you expect to see?

andl    $-33, %eax
subl    $65, %eax
cmpb    $25, %al
setbe   %al
movzbl  %al, %eax

This is what GCC 5.4.0 produces. I was surprised by this code, since I only expected it to combine the CMP + CMP to a SUB + CMP. But now that I see this, I'd like the Go compiler to produce similar code.

What did you see instead?

   MOVZX 0x8(SP), AX
   CMPL $0x41, AL
   JB L2
   CMPL $0x5a, AL
   JA L2
   MOVL $0x1, AX
L1:
   MOVB AL, 0x10(SP)
   RET
L2:
   CMPL $0x61, AL
   JB L3
   CMPL $0x7a, AL
   SETBE AL
   JMP L1
L3:
   XORL AX, AX
   JMP L1
@dsnet
Copy link
Member

dsnet commented Oct 7, 2016

Related to #16697

Can you test if this is fixed on tip?

@minux
Copy link
Member

minux commented Oct 7, 2016 via email

@rillig
Copy link
Contributor Author

rillig commented Oct 7, 2016

Tested with 78a267e. The generated code uses 11 instead of 15 instructions, which is good enough for now.

@rillig rillig closed this as completed Oct 7, 2016
@golang golang locked and limited conversation to collaborators Oct 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants