From 4c4bc0d0bb3354682b2473640c0bc8cbb9ea7eae Mon Sep 17 00:00:00 2001 From: Andrew Lenharth Date: Fri, 7 Jul 2023 16:27:10 -0500 Subject: [PATCH] [FIRRTL] incorrect canonicalization pattern (#5556) closes #5554 --- include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td | 8 +------- lib/Dialect/FIRRTL/FIRRTLFolds.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td b/include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td index 7ec924e83791..ca5892f13d5c 100644 --- a/include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td +++ b/include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td @@ -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))), diff --git a/lib/Dialect/FIRRTL/FIRRTLFolds.cpp b/lib/Dialect/FIRRTL/FIRRTLFolds.cpp index 5fd232037420..c1d3422a8fb4 100644 --- a/lib/Dialect/FIRRTL/FIRRTLFolds.cpp +++ b/lib/Dialect/FIRRTL/FIRRTLFolds.cpp @@ -579,10 +579,10 @@ OpFoldResult AndPrimOp::fold(FoldAdaptor adaptor) { void AndPrimOp::getCanonicalizationPatterns(RewritePatternSet &results, MLIRContext *context) { - results.insert(context); + results + .insert(context); } OpFoldResult OrPrimOp::fold(FoldAdaptor adaptor) {