Skip to content

Commit

Permalink
chore: revert changes to instruction_deduplication test
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Jan 5, 2024
1 parent 7770ca0 commit 5941a62
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ mod test {
instruction::{BinaryOp, Instruction, TerminatorInstruction},
map::Id,
types::Type,
value::{Value, ValueId},
value::Value,
},
};

Expand Down Expand Up @@ -293,24 +293,22 @@ mod test {
#[test]
fn instruction_deduplication() {
// fn main f0 {
// b0(v0: Field):
// v1 = truncate v0 to 32 bits, max_bit_size: 254
// v2 = cast v1 as u32
// v3 = truncate v0 to 32 bits, max_bit_size: 254
// v4 = cast v3 as u32
// constrain v2 v4
// b0(v0: u16):
// v1 = cast v0 as u32
// v2 = cast v0 as u32
// constrain v1 v2
// }
//
// After constructing this IR, we run constant folding which should replace the second truncation and cast
// After constructing this IR, we run constant folding which should replace the second cast
// with a reference to the results to the first. This then allows us to optimize away
// the constrain instruction as both inputs are known to be equal.
//
// The first truncation and cast instructions are retained and will be removed in the dead instruction elimination pass.
// The first cast instruction is retained and will be removed in the dead instruction elimination pass.
let main_id = Id::test_new(0);

// Compiling main
let mut builder = FunctionBuilder::new("main".into(), main_id, RuntimeType::Acir);
let v0 = builder.add_parameter(Type::field());
let v0 = builder.add_parameter(Type::unsigned(16));

let v1 = builder.insert_cast(v0, Type::unsigned(32));
let v2 = builder.insert_cast(v0, Type::unsigned(32));
Expand All @@ -319,28 +317,21 @@ mod test {
let mut ssa = builder.finish();
let main = ssa.main_mut();
let instructions = main.dfg[main.entry_block()].instructions();
assert_eq!(instructions.len(), 5);
assert_eq!(instructions.len(), 3);

// Expected output:
//
// fn main f0 {
// b0(v0: Field):
// v1 = truncate v0 to 32 bits, max_bit_size: 254
// v2 = cast v1 as u32
// b0(v0: u16):
// v1 = cast v1 as u32
// }
let ssa = ssa.fold_constants();
let main = ssa.main();
let instructions = main.dfg[main.entry_block()].instructions();

assert_eq!(instructions.len(), 2);
assert_eq!(instructions.len(), 1);
let instruction = &main.dfg[instructions[0]];

assert_eq!(
&main.dfg[instructions[0]],
&Instruction::Truncate { value: v0, bit_size: 32, max_bit_size: 254 }
);
assert_eq!(
&main.dfg[instructions[1]],
&Instruction::Cast(ValueId::test_new(5), Type::unsigned(32))
);
assert_eq!(instruction, &Instruction::Cast(v0, Type::unsigned(32)));
}
}

0 comments on commit 5941a62

Please sign in to comment.