Skip to content

Commit 816fa85

Browse files
TomAFrenchjfecher
andauthoredFeb 8, 2024
feat: perform constraints on uncasted values if they are the same type (#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>
1 parent 41ee1aa commit 816fa85

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎compiler/noirc_evaluator/src/ssa/ir/instruction/constrain.rs

+17
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,23 @@ pub(super) fn decompose_constrain(
120120
}
121121
}
122122

123+
(
124+
Value::Instruction { instruction: instruction_lhs, .. },
125+
Value::Instruction { instruction: instruction_rhs, .. },
126+
) => {
127+
match (&dfg[*instruction_lhs], &dfg[*instruction_rhs]) {
128+
// Casting two values just to enforce an equality on them.
129+
//
130+
// This is equivalent to enforcing equality on the original values.
131+
(Instruction::Cast(original_lhs, _), Instruction::Cast(original_rhs, _))
132+
if dfg.type_of_value(*original_lhs) == dfg.type_of_value(*original_rhs) =>
133+
{
134+
vec![Instruction::Constrain(*original_lhs, *original_rhs, msg.clone())]
135+
}
136+
137+
_ => vec![Instruction::Constrain(lhs, rhs, msg.clone())],
138+
}
139+
}
123140
_ => vec![Instruction::Constrain(lhs, rhs, msg.clone())],
124141
}
125142
}

0 commit comments

Comments
 (0)
Please sign in to comment.