cmd/compile: switch statements over strings are not optimal #33934
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
I played around with some switch statements over strings to check how the gc would behave.
For example, the switch in the following function has some issues (https://godbolt.org/z/L-Z-TM):
What did you expect to see?
I expected the generated assembly code to be relatively simple, with no redundant instructions or jumps.
What did you see instead?
Instead, I can see some redundancies in the output of the compiler (below, I will be referring to the lines in the website mentioned above):
x == "1"
usesruntime.cmpstring
, while the others compare x directly with an intlen(x) == 0
, which is never true, give that the check on line 16 has failedreturn -3
blockjeq
->jeq
andjeq
->jne
)The text was updated successfully, but these errors were encountered: