This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] use right register class for input operand of XXPERMDIs
AbandonedPublic

Authored by shchenz on Nov 4 2021, 3:35 AM.

Details

Reviewers
jsji
nemanjai
Group Reviewers
Restricted Project
Summary

This is from code review comments for D106555

In D106555, after we added:

def : Pat<(v2i64 (PPCzextldsplat ForceXForm:$A)),
          (v2i64 (XXPERMDIs (LFIWZX ForceXForm:$A), 0))>;
def : Pat<(v2i64 (PPCsextldsplat ForceXForm:$A)),
          (v2i64 (XXPERMDIs (LFIWAX ForceXForm:$A), 0))>;

some LIT cases change the input for vector splat instruction from vs0 to f0. But for vector splat instruction, like xxspltd, vs0 makes more sense than f0.

This patch changes register class for XXPERMDIs from vsfrc to vsrc. Now XXPERMDIs has same input type with XXPERMDI. So that it needs a vector register instead of a scalar float register.

Some other vector instructions have same issue, like XXSLDWI/XXSLDWIs, XXSPLTW/XXSPLTWs.

Diff Detail

Event Timeline

shchenz created this revision.Nov 4 2021, 3:35 AM
shchenz requested review of this revision.Nov 4 2021, 3:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2021, 3:35 AM
shchenz retitled this revision from [PowerPC] use right register class for XXPERMDIs to [PowerPC] use right register class for input operand of XXPERMDIs.Nov 4 2021, 4:00 AM
jsji added inline comments.Nov 4 2021, 6:46 AM
llvm/lib/Target/PowerPC/PPCInstrVSX.td
1069

I believe the intention was to use XXPERMDIs for single precision , for vsfrc, while XXPERMDI for vsrc.
Are we sure we are using XXPERMDIs correctly in D106555?

shchenz marked an inline comment as done.Nov 4 2021, 10:42 PM
shchenz added inline comments.
llvm/lib/Target/PowerPC/PPCInstrVSX.td
1069
def XXPERMDIs : XX3Form_2s<60, 10, (outs vsrc:$XT), (ins vsfrc:$XA, u2imm:$DM),
                           "xxpermdi $XT, $XA, $XA, $DM", IIC_VecPerm, []>;

XXPERMDIs should be an operation based on doubleword. I think the suffix s is for same, which means register operand are both the same?

Compared with XXPERMDI:

def XXPERMDI : XX3Form_2<60, 10,
                     (outs vsrc:$XT), (ins vsrc:$XA, vsrc:$XB, u2imm:$DM),
                     "xxpermdi $XT, $XA, $XB, $DM", IIC_VecPerm,
                     [(set v2i64:$XT, (PPCxxpermdi v2i64:$XA, v2i64:$XB,
                       imm32SExt16:$DM))]>;

VSFRC is for f64, VSSRC is for f32, vsrc is for a vector type?

qiucf added a subscriber: qiucf.Nov 5 2021, 3:00 AM
qiucf added inline comments.
llvm/lib/Target/PowerPC/PPCInstrVSX.td
1069

Yes:

  • F8RC contains first 64 double
  • VFRC contains second 64 double
  • VSLRC contains first 64 vector
  • VRRC contains second 64 vector
  • VSSRC contains all 128 float
  • VSFRC contains all 128 double
  • VSRC contains all 128 vector

I am not in favour of this patch. The reasons I added XXPERMDIs a long time ago are:

  1. To allow a single input operand for single register splat/swap. This is useful when the input is a load (since due to chains, having a load as an input will end up with both loads emitted - i.e. no CSE).
  2. Since this is primarily useful for loads that load a partial vector (LFIWZX, etc.) the input register class is vsfrc (i.e. all scalar floating point registers).

Switching the register class to vsrc does end up producing the name of a VSX register, but I consider that a positive thing. It clearly shows the reader that this is operating on a partial vector. Of course the distinction is purely aesthetic, but I think it helps readability.

jsji added a comment.Nov 5 2021, 6:51 AM

Of course the distinction is purely aesthetic, but I think it helps readability.

Yes, this help readability when there are large number of instructions between lfiwax and xxspltd.
But this does introduce confusion about register classes -- it is suspicious that xxspltd operate on f0 instead of vs0.

I am OK with leaving it as it is, but I think we should at least add some comments in XXPERMDIs to clarify this register class change.

shchenz marked an inline comment as done.Nov 5 2021, 6:34 PM

Of course the distinction is purely aesthetic, but I think it helps readability.

Yes, this help readability when there are large number of instructions between lfiwax and xxspltd.
But this does introduce confusion about register classes -- it is suspicious that xxspltd operate on f0 instead of vs0.

I have the same feeling about the f0 instead of vs0. In Power ISA, instruction format for xxpermdi is like: xxpermdi XT,XA,XB,DM. I think XT, XA, XB are all for VSR register index even when XA == XB.

I am OK with leaving it as it is, but I think we should at least add some comments in XXPERMDIs to clarify this register class change.

OK, then I will abandon this patch, and commit an NFC patch to explain the different register classes for XXPERMDIs and XXPERMDI

Thanks for your review @nemanjai @jsji

...
But this does introduce confusion about register classes -- it is suspicious that xxspltd operate on f0 instead of vs0.

Ha ha, yup! Confusion about register classes is kind of a fact of life with PPC's complex overlaying of registers in a single register file. It certainly takes some time to get your mind around FP/VR/VSR/ACC registers.

But in any case, the neat feature of something like xxspltd vs34, f0, 0 is that you know that vs0 is only expected to be partially defined. So seeing something like xxspltd vs34, f0, 1 should set off some alarm bells because we are splatting what is expected to be undefined. No such determination can be made for xxspltd vs34, vs0, 1 (without tracking down how vs0 was defined).

shchenz abandoned this revision.Nov 7 2021, 6:24 PM

NFC patch 7c6f5950f08d41017536575152fb765ba85a09a1 is committed for the required comments.

Based on the discussion, we should abandon this patch.