Skip to content

Commit

Permalink
feat: simplify chains of casts to be all in terms of the original `Va…
Browse files Browse the repository at this point in the history
…lueId` (#3984)

…

# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

After #3946, `Instruction::Cast` is idempotent so we can replace the
`ValueId` being casted with the input to previous casts.

## Additional Context



## Documentation\*

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

# PR Checklist\*

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

Co-authored-by: kevaundray <kevtheappdev@gmail.com>
  • Loading branch information
TomAFrench and kevaundray committed Jan 11, 2024
1 parent 3decf8d commit 2384d3e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,14 @@ impl Instruction {
/// that value is returned. Otherwise None is returned.
fn simplify_cast(value: ValueId, dst_typ: &Type, dfg: &mut DataFlowGraph) -> SimplifyResult {
use SimplifyResult::*;
let value = dfg.resolve(value);

if let Value::Instruction { instruction, .. } = &dfg[value] {
if let Instruction::Cast(original_value, _) = &dfg[*instruction] {
return SimplifiedToInstruction(Instruction::Cast(*original_value, dst_typ.clone()));
}
}

if let Some(constant) = dfg.get_numeric_constant(value) {
let src_typ = dfg.type_of_value(value);
match (src_typ, dst_typ) {
Expand Down

0 comments on commit 2384d3e

Please sign in to comment.