diff --git a/hercules_opt/src/sroa.rs b/hercules_opt/src/sroa.rs index 924c8d938a011a7925a7e3f6d1aaaa874e30be6b..6205421f176de205c699864f367fa46d069c08a7 100644 --- a/hercules_opt/src/sroa.rs +++ b/hercules_opt/src/sroa.rs @@ -160,6 +160,7 @@ pub fn sroa(editor: &mut FunctionEditor, reverse_postorder: &Vec<NodeID>, types: } } + #[derive(Debug)] enum WorkItem { Unhandled(NodeID), AllocatedPhi { @@ -176,9 +177,9 @@ pub fn sroa(editor: &mut FunctionEditor, reverse_postorder: &Vec<NodeID>, types: fields: IndexTree<NodeID>, }, AllocatedTernary { - first: NodeID, - second: NodeID, - third: NodeID, + cond: NodeID, + thn: NodeID, + els: NodeID, node: NodeID, fields: IndexTree<NodeID>, }, @@ -263,9 +264,9 @@ pub fn sroa(editor: &mut FunctionEditor, reverse_postorder: &Vec<NodeID>, types: field_map.insert(node, fields.clone()); item = WorkItem::AllocatedTernary { - first, - second, - third, + cond: first, + thn: second, + els: third, node, fields, }; @@ -387,37 +388,35 @@ pub fn sroa(editor: &mut FunctionEditor, reverse_postorder: &Vec<NodeID>, types: } } WorkItem::AllocatedTernary { - first, - second, - third, + cond, + thn, + els, node, fields, } => { - if let (Some(fst_fields), Some(snd_fields), Some(thd_fields)) = ( - field_map.get(&first), - field_map.get(&second), - field_map.get(&third), + if let (Some(thn_fields), Some(els_fields)) = ( + field_map.get(&thn), + field_map.get(&els), ) { fields - .zip(fst_fields) - .zip(snd_fields) - .zip(thd_fields) - .for_each(|idx, (((res, fst), snd), thd)| { + .zip(thn_fields) + .zip(els_fields) + .for_each(|idx, ((res, thn), els)| { to_insert.insert( res.idx(), Node::Ternary { - first: **fst, - second: **snd, - third: **thd, + first: cond, + second: **thn, + third: **els, op: TernaryOperator::Select, }, ); }); } else { worklist.push_back(WorkItem::AllocatedTernary { - first, - second, - third, + cond, + thn, + els, node, fields, }); diff --git a/hercules_samples/products.hir b/hercules_samples/products.hir new file mode 100644 index 0000000000000000000000000000000000000000..d09bb0fa43df6d8f6111facc77c970e36e69b101 --- /dev/null +++ b/hercules_samples/products.hir @@ -0,0 +1,3 @@ +fn test(x : prod(i32, f32), y: prod(i32, f32), b: bool) -> prod(i32, f32) + res = select(b, x, y) + r = return(start, res) diff --git a/juno_samples/products.jn b/juno_samples/products.jn index 6c14e67abb9490c951cd489f3fc00758602c8bd2..b97f1088e3ff502b203f3b866338be9aae481bc1 100644 --- a/juno_samples/products.jn +++ b/juno_samples/products.jn @@ -1,11 +1,7 @@ fn test_call(x : i32, y : f32) -> (i32, f32) { let res = (x, y); for i = 0 to 10 { - if i % 2 == 0 { - res.0 += 1; - } else { - res.1 *= 2.0; - } + res.0 += 1; } return res; }