diff --git a/lang/src/son.rs b/lang/src/son.rs index 2ea58427..b0a89990 100644 --- a/lang/src/son.rs +++ b/lang/src/son.rs @@ -305,6 +305,19 @@ impl Nodes { return Some(self.new_node(ty, K::BinOp { op: T::Mul }, [ctrl, rhs, new_rhs])); } + if op == T::Sub + && self[lhs].kind == (K::BinOp { op: T::Add }) + && let K::CInt { value: a } = self[rhs].kind + && let K::CInt { value: b } = self[self[lhs].inputs[2]].kind + { + let new_rhs = self.new_node_nop(ty, K::CInt { value: b - a }, [ctrl]); + return Some(self.new_node(ty, K::BinOp { op: T::Add }, [ + ctrl, + self[lhs].inputs[1], + new_rhs, + ])); + } + if op == T::Sub && self[lhs].kind == (K::BinOp { op }) { // (a - b) - c => a - (b + c) let &[_, a, b] = self[lhs].inputs.as_slice() else { unreachable!() };