Skip to content

Commit

Permalink
fix(ssa refactor): Change the result of simplifying Eq and Lt to bool (
Browse files Browse the repository at this point in the history
…#1672)

Change the result of simplifying Eq and Lt to bool
  • Loading branch information
jfecher authored Jun 13, 2023
1 parent a0cef17 commit 1d48929
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/noirc_evaluator/src/ssa_refactor/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,15 +549,21 @@ impl Binary {
dfg: &mut DataFlowGraph,
lhs: FieldElement,
rhs: FieldElement,
operand_type: Type,
mut operand_type: Type,
) -> Option<Id<Value>> {
let value = match self.operator {
BinaryOp::Add => lhs + rhs,
BinaryOp::Sub => lhs - rhs,
BinaryOp::Mul => lhs * rhs,
BinaryOp::Div => lhs / rhs,
BinaryOp::Eq => (lhs == rhs).into(),
BinaryOp::Lt => (lhs < rhs).into(),
BinaryOp::Eq => {
operand_type = Type::bool();
(lhs == rhs).into()
}
BinaryOp::Lt => {
operand_type = Type::bool();
(lhs < rhs).into()
}

// The rest of the operators we must try to convert to u128 first
BinaryOp::Mod => self.eval_constant_u128_operations(lhs, rhs)?,
Expand All @@ -567,7 +573,6 @@ impl Binary {
BinaryOp::Shl => self.eval_constant_u128_operations(lhs, rhs)?,
BinaryOp::Shr => self.eval_constant_u128_operations(lhs, rhs)?,
};
// TODO: Keep original type of constant
Some(dfg.make_constant(value, operand_type))
}

Expand Down

0 comments on commit 1d48929

Please sign in to comment.