Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 35 additions & 39 deletions compiler/noirc_evaluator/src/ssa/ir/dfg/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,47 +224,43 @@ pub(crate) fn simplify(
return SimplifiedTo(then_value);
}

if let Value::Instruction { instruction, .. } = &dfg[then_value] {
if let Instruction::IfElse {
then_condition: inner_then_condition,
then_value: inner_then_value,
..
} = dfg[*instruction]
{
if then_condition == inner_then_condition {
let instruction = Instruction::IfElse {
then_condition,
then_value: inner_then_value,
else_condition,
else_value,
};
return SimplifiedToInstruction(instruction);
}
// TODO: We could check to see if `then_condition == inner_else_condition`
// but we run into issues with duplicate NOT instructions having distinct ValueIds.
if let Some(Instruction::IfElse {
then_condition: inner_then_condition,
then_value: inner_then_value,
..
}) = dfg.get_local_or_global_instruction(then_value)
{
if then_condition == *inner_then_condition {
let instruction = Instruction::IfElse {
then_condition,
then_value: *inner_then_value,
else_condition,
else_value,
};
return SimplifiedToInstruction(instruction);
}
};

if let Value::Instruction { instruction, .. } = &dfg[else_value] {
if let Instruction::IfElse {
then_condition: inner_then_condition,
else_value: inner_else_value,
..
} = dfg[*instruction]
{
if then_condition == inner_then_condition {
let instruction = Instruction::IfElse {
then_condition,
then_value,
else_condition,
else_value: inner_else_value,
};
return SimplifiedToInstruction(instruction);
}
// TODO: We could check to see if `then_condition == inner_else_condition`
// but we run into issues with duplicate NOT instructions having distinct ValueIds.
// TODO: We could check to see if `then_condition == inner_else_condition`
// but we run into issues with duplicate NOT instructions having distinct ValueIds.
}

if let Some(Instruction::IfElse {
then_condition: inner_then_condition,
else_value: inner_else_value,
..
}) = dfg.get_local_or_global_instruction(else_value)
{
if then_condition == *inner_then_condition {
let instruction = Instruction::IfElse {
then_condition,
then_value,
else_condition,
else_value: *inner_else_value,
};
return SimplifiedToInstruction(instruction);
}
};
// TODO: We could check to see if `then_condition == inner_else_condition`
// but we run into issues with duplicate NOT instructions having distinct ValueIds.
}

if matches!(&typ, Type::Numeric(_)) {
let result = ValueMerger::merge_numeric_values(
Expand Down
6 changes: 6 additions & 0 deletions test_programs/execution_success/regression_8174/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "regression_8174"
type = "bin"
authors = [""]

[dependencies]
3 changes: 3 additions & 0 deletions test_programs/execution_success/regression_8174/Prover.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a = ["ABC", "CDE"]
b = true
return = [["LNV", "ZIH"]]
4 changes: 4 additions & 0 deletions test_programs/execution_success/regression_8174/src/main.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
global G_A: (str<3>, [str<3>; 2]) = ("AWQ", ["LNV", "ZIH"]);
unconstrained fn main(a: [str<3>; 2], b: bool) -> pub [[str<3>; 2]; 1] {
[if (!b) { a } else { G_A.1 }]
}
1 change: 1 addition & 0 deletions test_programs/execution_success/regression_8174/stdout.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[regression_8174] Circuit output: Vec([Vec([String("LNV"), String("ZIH")])])

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
Loading