Skip to content

Legalize signed comparisons with constants to unsigned comparisons #472

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Domkeykong
Copy link
Contributor

took a while until i realized i could use a select and let the lower-select pass introduce the branches.
unfortunately there are some artifacts with the comparisons beyond 8 bits, each byte is compared twice, once for equality and once for Unsigned Greater Equal.

fixes #470

Copy link
Member

@mysterymath mysterymath left a comment

Choose a reason for hiding this comment

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

Hey, great change! Have you hacked much on LLVM before?

ret i8 %conv2
}

define zeroext i8 @sgt_16(i16 noundef %x) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this still faster than the sequence before this change? If not, it seems better to add a TODO to the legalizer code and restrict the optimization to 8 bits for now. We may need some kind of additional combiner pass to clean up the output of the legalizer, but it's not something where I can guess the details offhand.

auto RHSConst = getIConstantVRegValWithLookThrough(RHS, MRI);
bool RHSIsZero = RHSConst && RHSConst->Value.isZero();

if (Pred == CmpInst::ICMP_SLT && RHSConst && !RHSIsZero) {
Copy link
Member

Choose a reason for hiding this comment

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

A short summary comment about why this is faster than the alternative would be helpful. It's difficult to read out of the implementation.

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.

Faster Signed Comparison to Constants
2 participants