Skip to content

Commit

Permalink
[FIRRTL] incorrect canonicalization pattern (#5556)
Browse files Browse the repository at this point in the history
closes #5554
  • Loading branch information
darthscsi authored Jul 7, 2023
1 parent 19a7ae3 commit 4c4bc0d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
8 changes: 1 addition & 7 deletions include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,11 @@ def AndOfSelf : Pat <
[(KnownWidth $x)]>;

/// and(x, pad(y, n)) -> pad(and(tail(x), y), n), x is unsigned
def AndOfPadU : Pat <
def AndOfPad : Pat <
(AndPrimOp:$old (either $x, (PadPrimOp:$pad $y, $n))),
(MoveNameHint $old, (PadPrimOp (AndPrimOp (TailPrimOp $x, (TypeWidthAdjust32 $x, $y)), $y), $n)),
[(KnownWidth $x), (UIntType $x), (EqualTypes $x, $pad)]>;

/// and(x, pad(y, n)) -> cat(head(x), and(tail(x), y)), x is signed
def AndOfPadS : Pat <
(AndPrimOp:$old (either $x, (PadPrimOp:$pad $y, $n))),
(MoveNameHint $old, (CatPrimOp (HeadPrimOp $x, (TypeWidthAdjust32 $x, $y)), (AndPrimOp (TailPrimOp $x, (TypeWidthAdjust32 $x, $y)), (AsUIntPrimOp $y)))),
[(KnownWidth $x), (SIntType $x), (EqualTypes $x, $pad)]>;

def AndOfAsSIntL : Pat<
(AndPrimOp:$old (AsSIntPrimOp $x), $y),
(MoveNameHint $old, (AndPrimOp $x, (AsUIntPrimOp $y))),
Expand Down
8 changes: 4 additions & 4 deletions lib/Dialect/FIRRTL/FIRRTLFolds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,10 +579,10 @@ OpFoldResult AndPrimOp::fold(FoldAdaptor adaptor) {

void AndPrimOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) {
results.insert<patterns::extendAnd, patterns::moveConstAnd,
patterns::AndOfZero, patterns::AndOfAllOne,
patterns::AndOfSelf, patterns::AndOfPadU, patterns::AndOfPadS,
patterns::AndOfAsSIntL, patterns::AndOfAsSIntR>(context);
results
.insert<patterns::extendAnd, patterns::moveConstAnd, patterns::AndOfZero,
patterns::AndOfAllOne, patterns::AndOfSelf, patterns::AndOfPad,
patterns::AndOfAsSIntL, patterns::AndOfAsSIntR>(context);
}

OpFoldResult OrPrimOp::fold(FoldAdaptor adaptor) {
Expand Down

0 comments on commit 4c4bc0d

Please sign in to comment.