-
Notifications
You must be signed in to change notification settings - Fork 47
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
polynomial-to-standard: error on integer width for poly.add when ring coefficientModulus width is less than coefficient width #990
Comments
cc @AlexanderViand @inbelic on this issue
I think so - but I will need to catch up on this particular pass pipeline. |
Thanks for bringing this up! I’ll add it to the list of “issues that show why we really need formal verification around mod_arith stuff”! I agree @ switching this pipeline over to mod_arith would be the best thing to make sure at least these kinds of issues only occur in one place xD |
Similar code as above, and would report error no matter
Note that
IR emitted here (one RemSi from add lowering, another from mul_scalar lowering) %4 = "arith.constant"() <{value = -1 : i32}> : () -> i32
%5 = "tensor.splat"(%4) : (i32) -> tensor<1024xi32>
%6 = "arith.muli"(%1, %5) <{overflowFlags = #arith.overflow<none>}> : (tensor<1024xi32>, tensor<1024xi32>) -> tensor<1024xi32>
%7 = "arith.constant"() <{value = 33538049 : i32}> : () -> i32
%8 = "arith.remsi"(%1, %7) : (tensor<1024xi32>, i32) -> tensor<1024xi32>
%10 = "arith.constant"() <{value = dense<33538049> : tensor<1024xi26>}> : () -> tensor<1024xi26>
%11 = "arith.extsi"(%3) : (tensor<1024xi32>) -> tensor<1024xi26>
%12 = "arith.extsi"(%8) : (tensor<1024xi32>) -> tensor<1024xi26>
%13 = "arith.addi"(%11, %12) <{overflowFlags = #arith.overflow<none>}> : (tensor<1024xi26>, tensor<1024xi26>) -> tensor<1024xi26>
%14 = "arith.remsi"(%13, %10) : (tensor<1024xi26>, tensor<1024xi26>) -> tensor<1024xi26>
%15 = "arith.trunci"(%14) : (tensor<1024xi26>) -> tensor<1024xi32> |
When playing around
tests/bgv/to_polynomial.mlir
with additional-convert-elementwise-to-affine -polynomial-to-standard
, error happenedReduced to a minimal working example with argument
-polynomial-to-standard
, where changing the line to!p = !p2
resolves the problem:The related code is the following
heir/lib/Conversion/PolynomialToStandard/PolynomialToStandard.cpp
Lines 522 to 543 in b79bccf
It assumes either coefficientModulus is a power-of-two or its width is the same as coefficientType.
Maybe we should check that coefficientType has the same width as coefficientModulus if it is a prime.
Also, should we consider lowering it to mod_arith so that polynomial-to-standard can be simplified? Currently extsi/extui is everywhere.
The text was updated successfully, but these errors were encountered: