Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIRRTL] Canonicalize away CVT and adjust all patterns which matched cvt #5527

Merged
merged 18 commits into from
Jul 5, 2023

Conversation

darthscsi
Copy link
Contributor

@darthscsi darthscsi commented Jun 30, 2023

closes #5524

@darthscsi darthscsi marked this pull request as ready for review June 30, 2023 15:19
Copy link
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix.

Can you include the test that triggered this?

Copy link
Contributor

@dtzSiFive dtzSiFive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, can we add the regression tests this fixes?

Looks nicer too, and that EqualIntSize was something I was reaching for earlier, thanks for adding!

This looks right but didn't deep dive it.

include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td Outdated Show resolved Hide resolved
include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td Outdated Show resolved Hide resolved
(AndPrimOp $x, (NativeCodeCall<"$_builder.create<ConstantOp>($0.getLoc(), cast<IntType>($0.getType()), $1.getValue().trunc($1.getValue().getBitWidth()-1).zext(*cast<IntType>($0.getType()).getWidth()))"> $x, $cst))
(AndPrimOp $x, (NativeCodeCall<"$_builder.create<ConstantOp>($0.getLoc(), "
"cast<IntType>($0.getType()), "
"$1.getValue().sextOrTrunc(cast<IntType>($0.getType()).getWidthOrSentinel()))"> $x, $cst))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 could this pattern work for non-constants (of known width) equally well, and let a different folder create the sextortrunc thing for us?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This can be done separately, partly just curious, it's of course more important to fix the issue, thanks!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was playing with a conversion via asSInt and then a width-narrowing pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have more robust width-narrowing in comb, and I'm inclined to do more of this stuff in comb where it's less error prone.

@darthscsi darthscsi changed the title [NFC] Fix and(cvt) size bug [FIRRTL] Canonicalize away CVT and adjust all patterns which matched cvt Jun 30, 2023
Copy link
Member

@seldridge seldridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not validated in excruciating detail. Looks fine, though.

include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td Outdated Show resolved Hide resolved
Comment on lines 518 to 525
def CVTUnSigned : Pat<
(CvtPrimOp:$old $x),
(MoveNameHint $old,
(AsSIntPrimOp
(CatPrimOp
(NativeCodeCall<"$_builder.create<ConstantOp>($0.getLoc(), APSInt(APInt()))"> $old),
$x))),
[(UIntType $x)]>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This canonicalization effectively removes the need for cvt. Maybe we just boot this from the spec or remove this during parsing and drop the operation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CVT primarily exists for inferred widths. It may be convenient in that context (e.g. at chisel emission), but I'm not sure.

Copy link
Member

@uenoku uenoku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@darthscsi darthscsi merged commit 8077de8 into main Jul 5, 2023
5 checks passed
calebmkim pushed a commit to andrewb1999/circt that referenced this pull request Jul 12, 2023
@darthscsi darthscsi deleted the dev/darthscsi/castcanon branch April 11, 2024 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FIRRTL] AndCvtU canonicalization crash, wrong result (when widths aren't same)
4 participants