google / google/heir

`operation-rebalancer` pass modifies IR so as to require additional relinearization ops

Open
#1,284 12 comments 0 reactions 2 assignees Claimed by @AlexanderViand-Intel View on GitHub
dialect: mgmt
Dominant language
MLIR
Stars
906
Forks
171
Avg merge
4d 12h
Merged PRs (30d)
32

Description

The optimizer generally does a good job of pulling relins through adds, but I found a very odd case here where it will work on `(p*x) + ((x*x)+(y*y))` but not on `((x*x)+(y*y)) + (p*x)`

```llvm
// heir-opt --mlir-to-secret-arithmetic --secret-insert-mgmt-bgv --optimize-relinearization
func.func @bar(%x: i16 {secret.secret}, %y: i16 {secret.secret}, %p: i16) -> (i16) {
%xx = arith.muli %x, %x : i16
%yy = arith.muli %y, %y : i16
%0 = arith.addi %xx, %yy : i16
%xp = arith.muli %x, %p : i16
%1 = arith.addi %0, %xp : i16
func.return %1 : i16
}
///produces a single relin
```

```llvm
// heir-opt --mlir-to-secret-arithmetic --secret-insert-mgmt-bgv --optimize-relinearization
func.func @bar(%x: i16 {secret.secret}, %y: i16 {secret.secret}, %p: i16) -> (i16) {
%xx = arith.muli %x, %x : i16
%yy = arith.muli %y, %y : i16
%0 = arith.addi %xx, %yy : i16
%xp = arith.muli %x, %p : i16
%1 = arith.addi %xp, %0 : i16
func.return %1 : i16
}
///produces two relins, despite the only change being the order of operands for %1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.