cmd/compile/internal/ssa: limit call stack use in known bits

Due to SSA properties, iterating over blocks postorder will make fold
encounter uses before their definition, ensuring that it recurses down
into the use-def chain. Iterating in reverse postorder minimizes this
recursion.

Change-Id: I7847c7384477d8c42d5d5586532cd9e26a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/770340
Auto-Submit: Jorropo <jorropo.pgm@gmail.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jorropo <jorropo.pgm@gmail.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
This commit is contained in:
Daniel Morsing 2026-04-24 05:55:53 +01:00 committed by Gopher Robot
parent 914b632202
commit be9da6ce60

View file

@ -4,6 +4,8 @@
package ssa
import "slices"
func (kb *knownBitsState) fold(v *Value) (value, known int64) {
if kb.seenValues.Test(uint32(v.ID)) {
return kb.entries[v.ID].value, kb.entries[v.ID].known
@ -167,7 +169,7 @@ func knownBits(f *Func) {
kb.reachableBlocks.Set(uint32(b.ID))
}
for _, b := range blocks {
for _, b := range slices.Backward(blocks) {
for _, v := range b.Values {
if v.Uses == 0 || !(v.Type.IsInteger() || v.Type.IsBoolean()) {
continue