This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] refactor convertToImmediateForm - NFC
ClosedPublic

Authored by shchenz on May 31 2020, 10:20 PM.

Details

Summary

This is a NFC patch to make convertToImmediateForm a light wrapper for converting xform and imm form instructions on PowerPC.

Diff Detail

Event Timeline

shchenz created this revision.May 31 2020, 10:20 PM
lkail added a subscriber: lkail.May 31 2020, 11:18 PM
lkail added inline comments.
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
3300

Can we use SignExtend64<16>(Imm) in MathExtra.h to simplify?

This is something that we wanted to do early before. Thank you for doing this. Some minor comments.

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
2663

Please update the comments as it is NOT always LI now.

2663–2664

I think, it makes more sense to do it as follows so that, we can add more peephole for Imm form

if (HasImmForm && transformToImmFormFedByLI) return true;
shchenz updated this revision to Diff 267800.Jun 2 2020, 12:29 AM
shchenz marked 5 inline comments as done.

address review comments

Thanks for your comments @lkail @steven.zhang

Patch updated.

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
2663

Not very clear about this comment.

transformToImmFormFedByLI will check LI opcode inside it like other functions transformToImmFormFedByLI & simplifyToLI

3300

good idea

steven.zhang added inline comments.Jun 2 2020, 1:54 AM
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
2663

Before moving the transformToImmFormFedByLi into the if clause, the comments didn't align with the implementation. It is ok now.

3425

It can be improved with APInt utility.

shchenz marked an inline comment as done.Jun 2 2020, 2:55 AM
shchenz added inline comments.
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
3425
APInt Mask = APInt::getBitsSetWithWrap(32, 32 - ME - 1, 32 - MB);
// Current APInt::getBitsSetWithWrap sets all bits to 0 if loBit is equal to highBit.
// If MB - ME == 1, we expect a full set mask instead of 0.
if (MBSrc - MESrc == 1)
   Mask.setAllBits();

Personally, I think using a raw APInt would be better than above statements?

shchenz marked an inline comment as done.Jun 2 2020, 3:12 AM
shchenz added inline comments.
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
3425

Should be a raw int... not raw APInt

steven.zhang added inline comments.Jun 2 2020, 4:24 AM
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
3425

If MB - ME == 1, the current implementation is still zero.

#include <stdio.h>

int main() {
         long long ME=23;
         long long MB = ME + 1;
         unsigned long long Mask = ((1LLU << (32 - MB)) - 1) & ~((1LLU << (31 - ME)) - 1);
         printf("%llx\n", Mask);
         return 0;
}

clang test.c;./a.out
0

shchenz marked an inline comment as done.Jun 2 2020, 5:52 AM
shchenz added inline comments.
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
3425

OK, thanks for pointing it out. Then the mask calculated here should be a bug. If MB - ME == 1, we expect full mask instead of zero mask.

I suggest we don't fix this in this NFC patch. This patch intends to make the convertToImmediateForm light and mostly move codes from convertToImmediateForm to new created function SimplifyToLI.

steven.zhang added inline comments.Jun 3 2020, 2:44 AM
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
3425

Agree.

steven.zhang accepted this revision.Jun 7 2020, 6:16 PM

Thank you for doing this to make the code more clear. LGTM now.

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
3400

Maybe, this is another case that can be improved with the APInt utility to make the code more clear.

This revision is now accepted and ready to land.Jun 7 2020, 6:16 PM
shchenz marked an inline comment as done.Jun 8 2020, 8:12 PM
shchenz added inline comments.
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
3400

Because InVal can be 32 or 64 bit width, we need to create different width Mask for them. But InVal &= Mask handles 32/64 bit raw integer automatically.

This revision was automatically updated to reflect the committed changes.