Skip to content

Conversation

@cowardsa
Copy link
Contributor

@cowardsa cowardsa commented Aug 29, 2025

Add support for extract, and logical shift operators to KnownBits analysis - helping to improve QoR for synth results. A future PR may aim to improve performance by invoking a caching mechanism that uses the MLIR analysis runners.

@cowardsa cowardsa requested a review from darthscsi as a code owner August 29, 2025 09:42
@cowardsa cowardsa changed the title [Comb [Comb] Expand Known-Bits Analysis to Additional Operators Aug 29, 2025
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. We need unit tests for this but I don't block the PR as there hasn't been a test for other operations as well.

Comment on lines +102 to +116
// `shl(x, y)` is the known bits of `x` << known bits of `y`.
if (auto shlOp = dyn_cast<ShlOp>(op)) {
auto lhs = computeKnownBits(shlOp.getOperand(0), depth + 1);
auto rhs = computeKnownBits(shlOp.getOperand(1), depth + 1);
auto res = KnownBits::shl(lhs, rhs);
return res;
}

// `shr(x, y)` is the known bits of `x` >> known bits of `y`.
if (auto shrOp = dyn_cast<ShrUOp>(op)) {
auto lhs = computeKnownBits(shrOp.getOperand(0), depth + 1);
auto rhs = computeKnownBits(shrOp.getOperand(1), depth + 1);
auto res = KnownBits::lshr(lhs, rhs);
return res;
}
Copy link
Member

Choose a reason for hiding this comment

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

Cool, didn't know that this smart shift API for KnownBits exists.

@cowardsa
Copy link
Contributor Author

@uenoku - sorry meant to add a question in the description. Don't think we have any existing KnownBits tests - any thoughts on where such tests should go? Would it require a test pass to be written?

@uenoku
Copy link
Member

uenoku commented Aug 29, 2025

I think we can create a unite test folder for Comb (here is for AIG and probably we can put IR and query knowBits analysis to them

const char *ir = R"MLIR(
) but test pass also makes sense to me

@cowardsa
Copy link
Contributor Author

cowardsa commented Sep 1, 2025

@uenoku and @fabianschuiki - added KnownBits tests - let me know what you think? Wanted to add them now as worth checking things are behaving as expected!

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.

Looks awesome, thank you for adding tests!

@cowardsa cowardsa merged commit 901aa61 into llvm:main Sep 2, 2025
7 checks passed
@cowardsa cowardsa deleted the coward/comb_known_bits branch October 20, 2025 16:14
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.

2 participants