diff --git a/lib/Transform/Arith/MulToAdd.pdll b/lib/Transform/Arith/MulToAdd.pdll index eab07c1..7cfcc8d 100644 --- a/lib/Transform/Arith/MulToAdd.pdll +++ b/lib/Transform/Arith/MulToAdd.pdll @@ -8,7 +8,7 @@ Constraint IsPowerOfTwo(attr: Attr) [{ // Currently, constraints that return values must be defined in C++ Constraint Halve(attr: Attr) -> Attr; -Pattern PowerOfTwoExpand with benefit(2) { +Pattern PowerOfTwoExpandRhs with benefit(2) { let root = op(op {value = const: Attr}, rhs: Value); IsPowerOfTwo(const); let halved: Attr = Halve(const); @@ -20,3 +20,16 @@ Pattern PowerOfTwoExpand with benefit(2) { replace root with newAdd; }; } + +Pattern PowerOfTwoExpandLhs with benefit(2) { + let root = op(lhs: Value, op {value = const: Attr}); + IsPowerOfTwo(const); + let halved: Attr = Halve(const); + + rewrite root with { + let newConst = op {value = halved}; + let newMul = op(lhs, newConst); + let newAdd = op(newMul, newMul); + replace root with newAdd; + }; +}