[go] cmd/compile: treat function parameters as probably constant in string comparison

0 views
Skip to first unread message

Gopher Robot (Gerrit)

unread,
Feb 27, 2026, 11:18:48 PM (18 hours ago) Feb 27
to Yongqi Jia, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, David Chase, Go LUCI, Keith Randall, Keith Randall, Jorropo, Daniel Morsing, Robert Griesemer, Matthew Dempsky, golang-co...@googlegroups.com

Gopher Robot submitted the change

Change information

Commit message:
cmd/compile/internal/test: add benchmark for string comparison operand order

Add BenchmarkStringEqParamOrder to verify that the operand order of
string equality comparisons (strs[i] == str vs str == strs[i]) does not
affect performance when the comparand is a function parameter.

This benchmark was written while investigating issue #74471. Extensive
benchmarking on both amd64 (Intel Xeon Gold 6148, linux) and arm64
(Apple M1 Pro, darwin) with 30 samples each showed that on Go tip the
compiler already generates equivalent code for both orderings, so no
compiler change is needed. The benchmark is retained as a regression
guard.

Updates #74471
Change-Id: I257910bba0abb3dc738578d898e63ecfb261c3cc
Reviewed-by: Keith Randall <k...@google.com>
Auto-Submit: Keith Randall <k...@golang.org>
Reviewed-by: David Chase <drc...@google.com>
Reviewed-by: Keith Randall <k...@golang.org>
Files:
  • M src/cmd/compile/internal/test/bench_test.go
Change size: M
Delta: 1 file changed, 54 insertions(+), 1 deletion(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +2 by Keith Randall, +1 by Keith Randall, +1 by David Chase
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I257910bba0abb3dc738578d898e63ecfb261c3cc
Gerrit-Change-Number: 742141
Gerrit-PatchSet: 4
Gerrit-Owner: Yongqi Jia <yongqi...@gmail.com>
Gerrit-Reviewer: David Chase <drc...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@google.com>
Gerrit-Reviewer: Matthew Dempsky <mat...@go.dev>
Gerrit-Reviewer: Robert Griesemer <g...@golang.org>
Gerrit-Reviewer: Yongqi Jia <yongqi...@gmail.com>
Gerrit-CC: Daniel Morsing <daniel....@gmail.com>
Gerrit-CC: Jorropo <jorro...@gmail.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages