diff options
author | khr@golang.org <khr@golang.org> | 2024-04-13 19:21:15 -0700 |
---|---|---|
committer | Keith Randall <khr@google.com> | 2024-04-19 16:31:02 +0000 |
commit | 1a0b86375fad202048adb88cba4caec535a52a45 (patch) | |
tree | 3ba0daeb3bbb608d528e895cb14fd3a860520595 /src/cmd/compile/internal/ssa/_gen/generic.rules | |
parent | d428a63875d335d1e1b9a3b3b45ad58f46e1e6bc (diff) | |
download | go-1a0b86375fad202048adb88cba4caec535a52a45.tar.gz go-1a0b86375fad202048adb88cba4caec535a52a45.zip |
cmd/compile: remove redundant calls to cmpstring
The results of cmpstring are reuseable if the second call has the
same arguments and memory.
Note that this gets rid of cmpstring, but we still generate a
redundant </<= test and branch afterwards, because the compiler
doesn't know that cmpstring only ever returns -1,0,1.
Update #61725
Change-Id: I93a0d1ccca50d90b1e1a888240ffb75a3b10b59b
Reviewed-on: https://go-review.googlesource.com/c/go/+/578835
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/compile/internal/ssa/_gen/generic.rules')
-rw-r--r-- | src/cmd/compile/internal/ssa/_gen/generic.rules | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/_gen/generic.rules b/src/cmd/compile/internal/ssa/_gen/generic.rules index 4c475d31e0..398601e81b 100644 --- a/src/cmd/compile/internal/ssa/_gen/generic.rules +++ b/src/cmd/compile/internal/ssa/_gen/generic.rules @@ -2794,3 +2794,12 @@ (Load <t> (OffPtr [off] (Convert (Addr {sym} _) _) ) _) && t.IsInteger() && t.Size() == 4 && isFixed32(config, sym, off) => (Const32 [fixed32(config, sym, off)]) (Load <t> (OffPtr [off] (ITab (IMake (Addr {sym} _) _))) _) && t.IsInteger() && t.Size() == 4 && isFixed32(config, sym, off) => (Const32 [fixed32(config, sym, off)]) (Load <t> (OffPtr [off] (ITab (IMake (Convert (Addr {sym} _) _) _))) _) && t.IsInteger() && t.Size() == 4 && isFixed32(config, sym, off) => (Const32 [fixed32(config, sym, off)]) + +// Calling cmpstring a second time with the same arguments in the +// same memory state can reuse the results of the first call. +// See issue 61725. +// Note that this could pretty easily generalize to any pure function. +(StaticLECall {f} x y m:(SelectN [1] c:(StaticLECall {g} x y mem))) + && isSameCall(f, "runtime.cmpstring") + && isSameCall(g, "runtime.cmpstring") +=> (MakeResult (SelectN [0] <typ.Int> c) m) |