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

feat: skip reading values immediately after it being written into an array #5449

Merged
merged 4 commits into from
Jul 12, 2024
Merged
Changes from all commits
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
12 changes: 12 additions & 0 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
@@ -602,6 +602,18 @@ impl Instruction {
}
}
Instruction::ArrayGet { array, index } => {
if let Value::Instruction { instruction, .. } = &dfg[*array] {
if let Instruction::ArraySet { index: write_index, value, .. } =
dfg[*instruction]
{
// If we're reading from an index of the array which we just wrote to, we can return
// the value which we wrote without performing the read.
if dfg.resolve(write_index) == dfg.resolve(*index) {
return SimplifiedTo(value);
}
}
}

let array = dfg.get_array_constant(*array);
let index = dfg.get_numeric_constant(*index);
if let (Some((array, _)), Some(index)) = (array, index) {

Unchanged files with check annotations Beta

Opcode::BlackBoxFuncCall(g) => write!(f, "{g}"),
Opcode::Directive(Directive::ToLeRadix { a, b, radix: _ }) => {
write!(f, "DIR::TORADIX ")?;

Check warning on line 156 in acvm-repo/acir/src/circuit/opcodes.rs

GitHub Actions / Code

Unknown word (TORADIX)
write!(
f,
// TODO (Note): this assumes that the decomposed bits have contiguous witness indices
match databus {
BlockType::Memory => write!(f, "INIT ")?,
BlockType::CallData => write!(f, "INIT CALLDATA ")?,
BlockType::ReturnData => write!(f, "INIT RETURNDATA ")?,

Check warning on line 187 in acvm-repo/acir/src/circuit/opcodes.rs

GitHub Actions / Code

Unknown word (RETURNDATA)
}
write!(f, "(id: {}, len: {}) ", block_id.0, init.len())
}
mod reflection {
//! Getting test failures? You've probably changed the ACIR serialization format.
//!
//! These tests generate C++ deserializers for [`ACIR bytecode`][super::circuit::Circuit]

Check warning on line 20 in acvm-repo/acir/src/lib.rs

GitHub Actions / Code

Unknown word (deserializers)
//! and the [`WitnessMap`] structs. These get checked against the C++ files committed to the `codegen` folder
//! to see if changes have been to the serialization format. These are almost always a breaking change!
//!
let iv = to_u8_array(initial_witness, iv)?;
let key = to_u8_array(initial_witness, key)?;
let ciphertext = aes128_encrypt(&scalars, iv, key)?;

Check warning on line 24 in acvm-repo/acvm/src/pwg/blackbox/aes128.rs

GitHub Actions / Code

Unknown word (ciphertext)
// Write witness assignments
for (output_witness, value) in outputs.iter().zip(ciphertext.into_iter()) {

Check warning on line 27 in acvm-repo/acvm/src/pwg/blackbox/aes128.rs

GitHub Actions / Code

Unknown word (ciphertext)
insert_value(output_witness, F::from(value as u128), initial_witness)?;
}
use pedersen::{pedersen, pedersen_hash};
pub(crate) use range::solve_range_opcode;
use signature::{
ecdsa::{secp256k1_prehashed, secp256r1_prehashed},

Check warning on line 33 in acvm-repo/acvm/src/pwg/blackbox/mod.rs

GitHub Actions / Code

Unknown word (prehashed)

Check warning on line 33 in acvm-repo/acvm/src/pwg/blackbox/mod.rs

GitHub Actions / Code

Unknown word (prehashed)
schnorr::schnorr_verify,
};
signature,
hashed_message: message,
output,
} => secp256k1_prehashed(

Check warning on line 148 in acvm-repo/acvm/src/pwg/blackbox/mod.rs

GitHub Actions / Code

Unknown word (prehashed)
initial_witness,
public_key_x,
public_key_y,
signature,
hashed_message: message,
output,
} => secp256r1_prehashed(

Check warning on line 162 in acvm-repo/acvm/src/pwg/blackbox/mod.rs

GitHub Actions / Code

Unknown word (prehashed)
initial_witness,
public_key_x,
public_key_y,
OpcodeResolutionError,
};
pub(crate) fn secp256k1_prehashed<F: AcirField>(

Check warning on line 16 in acvm-repo/acvm/src/pwg/blackbox/signature/ecdsa.rs

GitHub Actions / Code

Unknown word (prehashed)
initial_witness: &mut WitnessMap<F>,
public_key_x_inputs: &[FunctionInput<F>; 32],
public_key_y_inputs: &[FunctionInput<F>; 32],