Skip to content

Conversation

@uenoku
Copy link
Member

@uenoku uenoku commented Oct 4, 2025

Add LazyKoggeStonePrefixTree class for on-demand computation of prefix values, use lazy evaluation in ICmpOp conversion to avoid computing all intermediate prefix values. The class could be generalized to handle other prefix tree as well. KoggeStone is prioritized for now since it's currently used for wide comparisons (actually for smaller width it's not too bad to just rely on DCE). Locally checked LEC for larger width like i128 etc.

@uenoku uenoku force-pushed the dev/hidetou/lazy-Kogge-Stone branch from 6c9ce16 to ec10b65 Compare October 4, 2025 03:20
…arison lowering

Add LazyKoggeStonePrefixTree class for on-demand computation of prefix values, use lazy evaluation
in ICmpOp conversion to avoid computing all intermediate prefix values.
@uenoku uenoku force-pushed the dev/hidetou/lazy-Kogge-Stone branch from ec10b65 to a7acda3 Compare October 4, 2025 03:40
@uenoku uenoku requested a review from cowardsa October 5, 2025 21:09
Copy link
Contributor

@cowardsa cowardsa left a comment

Choose a reason for hiding this comment

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

LGTM - nice changes computing Brent-Kung lazily may be a bit more complex as it has backwards+forwards phases... But this one looks ideal - only minor comments

if (it != prefixCache.end())
return it->second;

assert(level > 0 && "level must be positive");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: perhaps a comment to justify that we're now moving to compute the values and we can only do that after level 0 would help - took me a minute to get that

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely, sorry for the confusion.

@uenoku
Copy link
Member Author

uenoku commented Oct 7, 2025

Brent-Kung

Yeah Brent-Kung would be really non-trivial and not sure if there is a clean way :) I'll probably prioritize Sklanskey as it's used in 32-bit comparison (which creates ~500 dead operations right now).

@uenoku uenoku merged commit 398cd5c into llvm:main Oct 7, 2025
7 checks passed
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