Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 2 additions & 4 deletions compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,14 @@ pub(crate) fn simplify(
if let Instruction::IfElse {
then_condition: inner_then_condition,
then_value: inner_then_value,
else_condition: inner_else_condition,
..
} = dfg[*instruction]
{
if then_condition == inner_then_condition {
let instruction = Instruction::IfElse {
then_condition,
then_value: inner_then_value,
else_condition: inner_else_condition,
else_condition,
else_value,
};
return SimplifiedToInstruction(instruction);
Expand All @@ -250,7 +249,6 @@ pub(crate) fn simplify(
if let Value::Instruction { instruction, .. } = &dfg[else_value] {
if let Instruction::IfElse {
then_condition: inner_then_condition,
else_condition: inner_else_condition,
else_value: inner_else_value,
..
} = dfg[*instruction]
Expand All @@ -259,7 +257,7 @@ pub(crate) fn simplify(
let instruction = Instruction::IfElse {
then_condition,
then_value,
else_condition: inner_else_condition,
else_condition,
Comment thread
vezenovm marked this conversation as resolved.
else_value: inner_else_value,
};
return SimplifiedToInstruction(instruction);
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ impl<'f> Context<'f> {
self.inserter.function.dfg.make_constant(FieldElement::one(), NumericType::bool())
}
};

Comment thread
vezenovm marked this conversation as resolved.
Outdated
let enable_side_effects = Instruction::EnableSideEffectsIf { condition };
let call_stack = self.inserter.function.dfg.get_value_call_stack_id(condition);
self.insert_instruction_with_typevars(enable_side_effects, None, call_stack);
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/ssa/ssa_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ impl FunctionContext<'_> {
/// ```
fn codegen_if(&mut self, if_expr: &ast::If) -> Result<Values, RuntimeError> {
let condition = self.codegen_non_tuple_expression(&if_expr.condition)?;

Comment thread
vezenovm marked this conversation as resolved.
Outdated
if let Some(result) = self.try_codegen_constant_if(condition, if_expr) {
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "nested_if_then_block_same_cond"
type = "bin"
authors = [""]

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
a = 0
b = [[1, 0], [1, 0], [1, 1]]

return = [1, 0]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Regression taken from issue #7961 (https://github.com/noir-lang/noir/issues/7961)
fn main(a: bool, b: [[bool; 2]; 3]) -> pub [bool; 2] {
if (!!a) {
if (!!a) {
b[0]
} else {
b[0]
}
} else {
b[0]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[nested_if_then_block_same_cond] Circuit output: Vec([Field(1), Field(0)])

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading