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

Group commutative ops with constants #297

Closed
Pangoraw opened this issue Jan 30, 2025 · 1 comment · Fixed by #301
Closed

Group commutative ops with constants #297

Pangoraw opened this issue Jan 30, 2025 · 1 comment · Fixed by #301

Comments

@Pangoraw
Copy link
Collaborator

Pangoraw commented Jan 30, 2025

module {
  func.func @main(%arg0: tensor<3xi64>) -> tensor<3xi64> {
    %c = stablehlo.constant dense<1> : tensor<3xi64>
    %0 = stablehlo.add %arg0, %c : tensor<3xi64>
    %1 = stablehlo.add %0, %c : tensor<3xi64>
    %2 = stablehlo.add %1, %c : tensor<3xi64>
    return %2 : tensor<3xi64>
  }
}

could be transformed to:

module {
  func.func @main(%arg0: tensor<3xi64>) -> tensor<3xi64> {
    %c = stablehlo.constant dense<3> : tensor<3xi64>
    %0 = stablehlo.add %arg0, %c : tensor<3xi64>
    return %0 : tensor<3xi64>
  }
}

with (%x + %cst0) + %cst1 -> %x + (%cst0 + %cst1)

Not sure if we can apply this for floats though.

@wsmoses
Copy link
Member

wsmoses commented Jan 30, 2025

Yeah here we can do add of (add x, c1), c2 -> add x (c1+c2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants