Skip to content

Commit

Permalink
feat: perform constraints on uncasted values if they are the same type (
Browse files Browse the repository at this point in the history
#4303)

# Description

## Problem\*

Followup to #4302.

## Summary\*

This PR unwraps `constrain cast(v0, typ) == cast(v1, typ)` into
`constrain v0 == v1`. This will potentially improve #4060 effectiveness
as we're moving this constraint information up the DFG.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.

---------

Co-authored-by: jfecher <jake@aztecprotocol.com>
  • Loading branch information
TomAFrench and jfecher authored Feb 8, 2024
1 parent 41ee1aa commit 816fa85
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,23 @@ pub(super) fn decompose_constrain(
}
}

(
Value::Instruction { instruction: instruction_lhs, .. },
Value::Instruction { instruction: instruction_rhs, .. },
) => {
match (&dfg[*instruction_lhs], &dfg[*instruction_rhs]) {
// Casting two values just to enforce an equality on them.
//
// This is equivalent to enforcing equality on the original values.
(Instruction::Cast(original_lhs, _), Instruction::Cast(original_rhs, _))
if dfg.type_of_value(*original_lhs) == dfg.type_of_value(*original_rhs) =>
{
vec![Instruction::Constrain(*original_lhs, *original_rhs, msg.clone())]
}

_ => vec![Instruction::Constrain(lhs, rhs, msg.clone())],
}
}
_ => vec![Instruction::Constrain(lhs, rhs, msg.clone())],
}
}
Expand Down

0 comments on commit 816fa85

Please sign in to comment.