Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
randall77 opened this Issue May 23, 2016 · 3 comments

Comments

Projects
None yet
7 participants
@randall77
Copy link
Contributor

randall77 commented May 23, 2016

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?)

@randall77 randall77 added this to the Go1.8 milestone May 23, 2016

@quentinmit quentinmit added the NeedsFix label Oct 11, 2016

@rsc rsc modified the milestones: Go1.9, Go1.8 Oct 21, 2016

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented May 10, 2017

CL https://golang.org/cl/43157 mentions this issue.

@josharian josharian modified the milestones: Go1.10, Go1.9 May 18, 2017

josharian added a commit to josharian/go that referenced this issue May 23, 2017

cmd/compile: optimize signed n % c == 0
While we're here, also convert a - b == 0 to a == b.

Fixes golang#15806

Change-Id: I41f6f154cb9607d335a79542e05c2e19ce10f3dc

@bradfitz bradfitz modified the milestones: Go1.10, Go1.11 Nov 10, 2017

josharian added a commit to josharian/go that referenced this issue May 8, 2018

cmd/compile: optimize signed n % c == 0
While we're here, also convert a - b == 0 to a == b.

Fixes golang#15806

Change-Id: I41f6f154cb9607d335a79542e05c2e19ce10f3dc

@bradfitz bradfitz modified the milestones: Go1.11, Go1.12 Jun 19, 2018

@odeke-em

This comment has been minimized.

Copy link
Member

odeke-em commented Feb 4, 2019

We didn't get this in for Go1.12, so I'll move it to Go1.13 or perhaps "Unreleased" if we deem it to belong there.

@gopherbot

This comment has been minimized.

Copy link

gopherbot commented Mar 18, 2019

Change https://golang.org/cl/168038 mentions this issue: cmd/compile: add signed divisibility by power of 2 rules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.