Skip to content

cmd/compile: possible issue in optimization of -(c+-x) #31888

Closed

Description

@josharian

amd64.rules contains this rule:

(NEGQ (ADDQconst [c] (NEGQ x))) && c != -(1<<31) -> (ADDQconst [-c] x)

It was added in https://go-review.googlesource.com/c/go/+/38311/.

I don't understand the constraint c != -(1<<31): Why it is necessary at all, and if it is necessary, why it isn't say -(1<<63). If it does need to be -(1<<63), then we may be generating bad code. As such, tentatively marking Go 1.13.

cc @randall77

Activity

  1. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on May 7, 2019
  2. added this to the Go1.13 milestone on May 7, 2019
  3. randall77 commented on May 7, 2019

    @randall77
    Contributor

    ADDQconst on x86 requires that c be an int32.

    That's why the restriction is there, so that we don't generate an ADDQconst of 1<<31 (which is invalid) from an ADDQconst of -1<<31 (which is valid).

  4. josharian commented on May 7, 2019

    @josharian
    ContributorAuthor

    Ah! Thanks.

  5. gopherbot commented on May 7, 2019

    @gopherbot
    Contributor

    Change https://golang.org/cl/175778 mentions this issue: cmd/compile: add more Neg/Com optimizations

  6. locked and limited conversation to collaborators on May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions