Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 17 additions & 2 deletions compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,24 @@ impl<'block, Registers: RegisterAllocator> BrilligBlock<'block, Registers> {

let array_variable = self.convert_ssa_value(*array, dfg);

let index_variable = self.convert_ssa_single_addr_value(*index, dfg);
// If the index is a constant we can directly fetch the value from the brillig array or vector
// by skipping the `[RC, ...` (for arrays) or `[RC, Size, Capacity, ...` (for vectors) elements.
let index_constant = dfg.get_numeric_constant(*index);
let index_variable = if let Some(index_constant) = index_constant {
let offset = if matches!(dfg.type_of_value(*array), Type::Array(..)) {
// Brillig arrays are [RC, ...items]
1u128
} else {
// Brillig vectors are [RC, Size, Capacity, ...items]
3u128
};
let shifted_index = index_constant + offset.into();
self.brillig_context.make_usize_constant_instruction(shifted_index)
} else {
self.convert_ssa_single_addr_value(*index, dfg)
};

if dfg.is_constant(*index) {
if index_constant.is_some() {
self.brillig_context.codegen_load_with_offset(
array_variable.extract_register(),
index_variable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,6 @@ mod tests {
";

let ssa = Ssa::from_str(src).unwrap();
// Need to run SSA pass that sets up Brillig array gets
let ssa = ssa.brillig_array_gets();
// Need to run DIE to generate the used globals map, which is necessary for Brillig globals generation.
let mut ssa = ssa.dead_instruction_elimination();

Expand Down
9 changes: 0 additions & 9 deletions compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,6 @@ pub fn primary_passes(options: &SsaEvaluatorOptions) -> Vec<SsaPass> {
// Remove any potentially unnecessary duplication from the Brillig entry point analysis.
SsaPass::new(Ssa::remove_unreachable_functions, "Removing Unreachable Functions"),
SsaPass::new(Ssa::remove_truncate_after_range_check, "Removing Truncate after RangeCheck"),
// This pass makes transformations specific to Brillig generation.
// It must be the last pass to either alter or add new instructions before Brillig generation,
// as other semantics in the compiler can potentially break (e.g. inserting instructions).
// We can safely place the pass before DIE as that pass only removes instructions.
// We also need DIE's tracking of used globals in case the array get transformations
// end up using an existing constant from the globals space.
SsaPass::new(Ssa::brillig_array_gets, "Brillig Array Get Optimizations"),
SsaPass::new(Ssa::dead_instruction_elimination, "Dead Instruction Elimination"),
// A function can be potentially unreachable post-DIE if all calls to that function were removed.
SsaPass::new(Ssa::remove_unreachable_functions, "Removing Unreachable Functions"),
Expand Down Expand Up @@ -247,8 +240,6 @@ pub fn minimal_passes() -> Vec<SsaPass<'static>> {
SsaPass::new(Ssa::remove_unreachable_functions, "Removing Unreachable Functions"),
// We need a DIE pass to populate `used_globals`, otherwise it will panic later.
SsaPass::new(Ssa::dead_instruction_elimination, "Dead Instruction Elimination"),
// We need to add an offset to constant array indices in Brillig.
SsaPass::new(Ssa::brillig_array_gets, "Brillig Array Get Optimizations"),
]
}

Expand Down
150 changes: 0 additions & 150 deletions compiler/noirc_evaluator/src/ssa/opt/brillig_array_gets.rs

This file was deleted.

2 changes: 0 additions & 2 deletions compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,8 +1575,6 @@ mod test {
}
";
let ssa = Ssa::from_str(src).unwrap();
// Need to run SSA pass that sets up Brillig array gets
let ssa = ssa.brillig_array_gets();
let brillig = ssa.to_brillig(&BrilligOptions::default());

let ssa = ssa.fold_constants_with_brillig(&brillig);
Expand Down
1 change: 0 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mod array_set;
mod as_slice_length;
mod assert_constant;
mod basic_conditional;
mod brillig_array_gets;
pub(crate) mod brillig_entry_points;
mod check_u128_mul_overflow;
mod checked_to_unchecked;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Loading