Skip to content

cmd/compile: signed rounding adjustments unnecessary when comparing modulus to 0 #15806

@randall77

Description

@randall77
func f(i int) bool {
    return i%16 == 0
}

Since the modulo is signed, we have to do adjustments in case i is negative. We do

  adj := i>>63 & 15
  div := (i + adj) >> 4
  mod := i - div*16
  return mod == 0

Since we're comparing against 0, the adjustment in the first line is unnecessary. Zeroness is unaffected by the adjustment.
Might be as simple as converting (Eq (Mod64 x y) (Const64 [0])) to (Eq (Mod64u x y) (Const64 [0])) (and #uses of Mod64 is 1?)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions