This is an archive of the discontinued LLVM Phabricator instance.

[Support] Add KnownBits::concat method
ClosedPublic

Authored by RKSimon on Jul 26 2022, 2:47 AM.

Details

Summary

Add a method for the various cases where we need to concatenate 2 KnownBits together (BUILD_PAIR and SHIFT_PARTS in particular) - uses the existing APInt::concat 'HiBits.concat(LoBits)' convention

Diff Detail

Event Timeline

RKSimon created this revision.Jul 26 2022, 2:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2022, 2:47 AM
RKSimon requested review of this revision.Jul 26 2022, 2:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2022, 2:47 AM
foad added a comment.Jul 26 2022, 3:00 AM

Seems reasonable. The API is a bit different from APInt::concat, but I never particularly liked that API anyway :)

llvm/include/llvm/Support/KnownBits.h
316

Maybe just return { Hi.Zero.concat(Lo.Zero), Hi.One.concat(Lo.One) }?

RKSimon added inline comments.Jul 26 2022, 3:04 AM
llvm/include/llvm/Support/KnownBits.h
316

Hmm - I'd forgotten about APInt::concat - I guess we should try to make a similar KnownBits::concat ? We do tend to make them match where possible

foad added a subscriber: lattner.Jul 26 2022, 4:13 AM
foad added inline comments.
llvm/include/llvm/Support/KnownBits.h
316

I guess we should try to make a similar KnownBits::concat ?

Dunno. @lattner gave reasons for the API of the member function APInt::concat in D109620. I'm not sure if those reasons also apply to a non-member version - i.e. should it take (hi, lo) instead of (lo, hi)? Personally I prefer the (lo, hi) order.

RKSimon planned changes to this revision.Jul 26 2022, 4:33 AM

Yeah, I strongly think we should keep these consistent. At the same time, I don't care which design wins, feel free to pick which approach makes most sense to you.

RKSimon updated this revision to Diff 448376.Jul 28 2022, 10:33 AM
RKSimon retitled this revision from [Support] Add KnownBits::concatBits helper to [Support] Add KnownBits::concat method.
RKSimon edited the summary of this revision. (Show Details)
RKSimon added a reviewer: foad.

Refactor to match APInt::concat

foad accepted this revision.Jul 28 2022, 12:33 PM
This revision is now accepted and ready to land.Jul 28 2022, 12:33 PM
This revision was automatically updated to reflect the committed changes.