Skip to content

Commit 1b47fde

Browse files
committed
cmd/compile: clarify division bounds check optimization
The name of the function should mention division. Eliminate double negatives from the comment describing it. Change-Id: Icef1a5139b3a91b86acb930af97938f5160f7342 Reviewed-on: https://go-review.googlesource.com/c/go/+/217001 Run-TryBot: Josh Bleecher Snyder <[email protected]> Reviewed-by: Daniel Martí <[email protected]>
1 parent e932f0a commit 1b47fde

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

src/cmd/compile/internal/amd64/ssa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
257257

258258
// CPU faults upon signed overflow, which occurs when the most
259259
// negative int is divided by -1. Handle divide by -1 as a special case.
260-
if ssa.NeedsFixUp(v) {
260+
if ssa.DivisionNeedsFixUp(v) {
261261
var c *obj.Prog
262262
switch v.Op {
263263
case ssa.OpAMD64DIVQ:

src/cmd/compile/internal/ssa/prove.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,9 +1243,11 @@ func simplifyBlock(sdom SparseTree, ft *factsTable, b *Block) {
12431243
divdLim, divdLimok := ft.limits[divd.ID]
12441244
if (divrLimok && (divrLim.max < -1 || divrLim.min > -1)) ||
12451245
(divdLimok && divdLim.min > mostNegativeDividend[v.Op]) {
1246-
v.AuxInt = 1 // see NeedsFixUp in genericOps - v.AuxInt = 0 means we have not proved
1247-
// that the divisor is not -1 and the dividend is not the most negative,
1248-
// so we need to add fix-up code.
1246+
// See DivisionNeedsFixUp in rewrite.go.
1247+
// v.AuxInt = 1 means we have proved both that the divisor is not -1
1248+
// and that the dividend is not the most negative integer,
1249+
// so we do not need to add fix-up code.
1250+
v.AuxInt = 1
12491251
if b.Func.pass.debug > 0 {
12501252
b.Func.Warnl(v.Pos, "Proved %v does not need fix-up", v.Op)
12511253
}

src/cmd/compile/internal/ssa/rewrite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,8 +480,8 @@ func extend32Fto64F(f float32) float64 {
480480
return math.Float64frombits(r)
481481
}
482482

483-
// NeedsFixUp reports whether the division needs fix-up code.
484-
func NeedsFixUp(v *Value) bool {
483+
// DivisionNeedsFixUp reports whether the division needs fix-up code.
484+
func DivisionNeedsFixUp(v *Value) bool {
485485
return v.AuxInt == 0
486486
}
487487

src/cmd/compile/internal/x86/ssa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) {
199199
if v.Op == ssa.Op386DIVL || v.Op == ssa.Op386DIVW ||
200200
v.Op == ssa.Op386MODL || v.Op == ssa.Op386MODW {
201201

202-
if ssa.NeedsFixUp(v) {
202+
if ssa.DivisionNeedsFixUp(v) {
203203
var c *obj.Prog
204204
switch v.Op {
205205
case ssa.Op386DIVL, ssa.Op386MODL:

0 commit comments

Comments
 (0)