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

feat: mark division/modulo by constants as not requiring a predicate #7028

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: mark division/modulo by constants as not requiring a predicate
TomAFrench committed Jan 11, 2025
commit b8d333817b1694bc0b07d061c40e303872d9bd3e
17 changes: 9 additions & 8 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
@@ -407,7 +407,7 @@
// These can fail.
Constrain(..) | RangeCheck { .. } => true,

// This should never be side-effectful

Check warning on line 410 in compiler/noirc_evaluator/src/ssa/ir/instruction.rs

GitHub Actions / Code

Unknown word (effectful)
MakeArray { .. } | Noop => false,

// Some binary math can overflow or underflow
@@ -507,11 +507,10 @@
match self {
Binary(binary) => {
if matches!(binary.operator, BinaryOp::Div | BinaryOp::Mod) {
if let Some(rhs) = function.dfg.get_numeric_constant(binary.rhs) {
rhs != FieldElement::zero()
} else {
false
}
function
.dfg
.get_numeric_constant(binary.rhs)
.map_or(false, |rhs| !rhs.is_zero())
} else {
true
}
@@ -571,11 +570,13 @@
match self {
Instruction::Binary(binary) => {
match binary.operator {
BinaryOp::Div | BinaryOp::Mod => {
// Division and modulo operations can fail if the RHS is zero but is otherwise safe.
dfg.get_numeric_constant(binary.rhs).map_or(false, |rhs| !rhs.is_zero())
}
BinaryOp::Add { unchecked: false }
| BinaryOp::Sub { unchecked: false }
| BinaryOp::Mul { unchecked: false }
| BinaryOp::Div
| BinaryOp::Mod => {
| BinaryOp::Mul { unchecked: false } => {
// Some binary math can overflow or underflow, but this is only the case
// for unsigned types (here we assume the type of binary.lhs is the same)
dfg.type_of_value(binary.rhs).is_unsigned()