Skip to content

Commit

Permalink
add LHS/RHS versions of power of two pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
j2kun committed Jul 22, 2024
1 parent b26a7c9 commit 83053ed
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/Transform/Arith/MulToAdd.pdll
Original file line number Diff line number Diff line change
Expand Up @@ -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<arith.muli>(op<arith.constant> {value = const: Attr}, rhs: Value);
IsPowerOfTwo(const);
let halved: Attr = Halve(const);
Expand All @@ -20,3 +20,16 @@ Pattern PowerOfTwoExpand with benefit(2) {
replace root with newAdd;
};
}

Pattern PowerOfTwoExpandLhs with benefit(2) {
let root = op<arith.muli>(lhs: Value, op<arith.constant> {value = const: Attr});
IsPowerOfTwo(const);
let halved: Attr = Halve(const);

rewrite root with {
let newConst = op<arith.constant> {value = halved};
let newMul = op<arith.muli>(lhs, newConst);
let newAdd = op<arith.addi>(newMul, newMul);
replace root with newAdd;
};
}

0 comments on commit 83053ed

Please sign in to comment.