Skip to content

cmd/compile: opt should match rules through phis #53300

@Jorropo

Description

@Jorropo

The ssa opt pass currently abort matching if the rule go through a phis.

For example:

if c {
  y = -y
} else {
  y *= 2
}
x += y

Should be rewriten:

if c {
  x -= y
} else {
  x += y * 2
}

The necessary rules for that optimization already exists, but they can't be applied since a phi node is in the way.

When encountering a phi node opt should start a routine to apply the rule on all branches where that would remove uses of the previous values in that branch (this is because we don't want to generate dupped code that would slower) (and generate a new fallback block that applies the current operation for branches that didn't matched).

This could lead to a jump in codesize since multiple branches might have the same rules applies to them.
A pass that perform CSE but downward in the control flow would regain that lost space.

The extra compilation time cost might not be worth it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancecompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions