aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorJorropo <jorropo.pgm@gmail.com>2024-08-13 17:17:06 +0200
committerKeith Randall <khr@golang.org>2024-09-03 17:13:06 +0000
commit194fa2eb6cdeaddc4a89fae4610f99d8060d10a0 (patch)
tree32d0a4b7c36c7f60173f755abd11c30f5f2094fb /src/cmd
parent57df33814afc02bda314abea28ee8a3dc997505c (diff)
downloadgo-194fa2eb6cdeaddc4a89fae4610f99d8060d10a0.tar.xz
cmd/compile: compute Modu's maximum limits from argument's limits
addLocalFacts loop already ft.update which sets up limits correctly, but doing this in flowLimit help us since other values might depend on this limit. Updates #68857 We could improve this further: - remove mod alltogheter when we can prove a < b. - we could do more adhoc computation in flowLimit to set umax and umin tighter Change-Id: I5184913577b6a51a07cb53a6e6b73552a982de0b Reviewed-on: https://go-review.googlesource.com/c/go/+/605156 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/ssa/prove.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go
index 807f198787..c90b380096 100644
--- a/src/cmd/compile/internal/ssa/prove.go
+++ b/src/cmd/compile/internal/ssa/prove.go
@@ -1775,6 +1775,11 @@ func (ft *factsTable) flowLimit(v *Value) bool {
a := ft.limits[v.Args[0].ID]
b := ft.limits[v.Args[1].ID]
return ft.newLimit(v, a.mul(b.exp2(8), 8))
+ case OpMod64u, OpMod32u, OpMod16u, OpMod8u:
+ a := ft.limits[v.Args[0].ID]
+ b := ft.limits[v.Args[1].ID]
+ // Underflow in the arithmetic below is ok, it gives to MaxUint64 which does nothing to the limit.
+ return ft.unsignedMax(v, minU(a.umax, b.umax-1))
case OpPhi:
// Compute the union of all the input phis.
@@ -1909,6 +1914,8 @@ func addLocalFacts(ft *factsTable, b *Block) {
// Add facts about individual operations.
for _, v := range b.Values {
+ // FIXME(go.dev/issue/68857): this loop only set up limits properly when b.Values is in topological order.
+ // flowLimit can also depend on limits given by this loop which right now is not handled.
switch v.Op {
case OpAnd64, OpAnd32, OpAnd16, OpAnd8:
ft.update(b, v, v.Args[0], unsigned, lt|eq)