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: rulegen results in confusing compiler errors when reserved names are used in rewrite rules #45154

Closed
zhangfannie opened this issue Mar 22, 2021 · 2 comments
Assignees
Milestone

Comments

@zhangfannie
Copy link
Contributor

@zhangfannie zhangfannie commented Mar 22, 2021

Recently, I have a problem when I want to rewrite the following go codes with ARM64 REV16 instruction.

// go codes

 func genREV16(c uint64) uint64 {
        b := ((c & 0xff00ff00) >> 8) | ((c & 0x00ff00ff) << 8)
        return b
 }

The above codes can be optimized as two instructions "AND 0xffffffff, c, Rd" and "REV16 Rd". So I added the following rewritten rules to do this optimization.

((ADDshiftLL|ORshiftLL|XORshiftLL) <typ.UInt64> [8] (SRLconst [8] (ANDconst [a] x)) (ANDconst [b] x))
        && (uint64(a) == 0xff00ff00 && uint64(b) == 0x00ff00ff)
        => (REV16 (ANDconst <typ.UInt64> [0xffffffff] x))

But make.bash will report the error: "golong/src/cmd/compile/internal/ssa/rewriteARM64.go:1845: b.NewValue0 undefined (type int64 has no field or method NewValue0)".

@zhangfannie
Copy link
Contributor Author

@zhangfannie zhangfannie commented Mar 22, 2021

Thanks @josharian. Josh figured out the reason for the failure, which is the variable "b“ (and "v" and some others) is reserved in rewritten rules.

How can we improve the detection of reserved names? Thank you.

Loading

@mvdan mvdan changed the title A problem about the detection of reserved names in rewritten rules. cmd/compile: rulegen results in confusing compiler errors when reserved names are used in rewrite rules Mar 22, 2021
@mvdan mvdan self-assigned this Mar 22, 2021
@mvdan mvdan added this to the Go1.17 milestone Mar 22, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 22, 2021

Change https://golang.org/cl/303549 mentions this issue: cmd/compile: disallow rewrite rules from declaring reserved names

Loading

@gopherbot gopherbot closed this in 5437b5a Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants