Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add regression test for #5756 #5770

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,4 +843,57 @@ mod test {
let instructions = main.dfg[main.entry_block()].instructions();
assert_eq!(instructions.len(), 10);
}

// Regression for https://github.com/noir-lang/noir/issues/5756
#[test]
#[should_panic]
fn constant_array_deduplication() {
// fn main f0 {
// b0(v0: u64):
// v5 = call keccakf1600([v0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0])
// v6 = call keccakf1600([v0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0, u64 0])
// }
//
// Here we're checking a situation where two identical arrays are being initialized twice and being assigned separate `ValueId`s.
// This would result in otherwise identical instructions not being deduplicated.
let main_id = Id::test_new(0);

// Compiling main
let mut builder = FunctionBuilder::new("main".into(), main_id);
let v0 = builder.add_parameter(Type::unsigned(64));
let zero = builder.numeric_constant(0u128, Type::unsigned(64));
let typ = Type::Array(Arc::new(vec![Type::unsigned(64)]), 25);

let array_contents = vec![
v0, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero,
zero, zero, zero, zero, zero, zero, zero, zero, zero, zero,
];
let array1 = builder.array_constant(array_contents.clone().into(), typ.clone());
let array2 = builder.array_constant(array_contents.into(), typ.clone());

assert_eq!(array1, array2, "arrays were assigned different value ids");

let keccakf1600 =
builder.import_intrinsic("keccakf1600").expect("keccakf1600 intrinsic should exist");
let _v10 = builder.insert_call(keccakf1600, vec![array1], vec![typ.clone()]);
let _v11 = builder.insert_call(keccakf1600, vec![array2], vec![typ.clone()]);

let ssa = builder.finish();

println!("{ssa}");

let main = ssa.main();
let instructions = main.dfg[main.entry_block()].instructions();
let starting_instruction_count = instructions.len();
assert_eq!(starting_instruction_count, 3);

let ssa = ssa.fold_constants();

println!("{ssa}");

let main = ssa.main();
let instructions = main.dfg[main.entry_block()].instructions();
let ending_instruction_count = instructions.len();
assert_eq!(ending_instruction_count, 1);
}
}
Loading