This is an archive of the discontinued LLVM Phabricator instance.

[mips] Expansion of ROL and ROR macros
ClosedPublic

Authored by obucina on Jun 22 2015, 12:31 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

obucina updated this revision to Diff 28147.Jun 22 2015, 12:31 PM
obucina retitled this revision from to Expansion of ROL and ROR instructions.
obucina updated this object.
obucina edited the test plan for this revision. (Show Details)
obucina added reviewers: zoran.jovanovic, dsanders.
obucina added a subscriber: Unknown Object (MLST).
dsanders requested changes to this revision.Jun 23 2015, 3:30 AM
dsanders edited edge metadata.

There's quite a lot of formatting and coding standard nits in this patch. I'd recommend looking into clang-format-diff.py or git-clang-format since this will automate fixing most of the formatting nits that occur in the C++.

The main non-formatting comment I have is that this patch doesn't seem to account for the case when ror/rol/rorv/rolv are instructions rather than macros. It looks like it will expand even when the instructions are available. The other one is that the zero-immediate case should only emit a single instruction.

lib/Target/Mips/AsmParser/MipsAsmParser.cpp
2467 ↗(On Diff #28147)

Is this 80 cols? It looks rather long in phabricator

2474–2475 ↗(On Diff #28147)

Nit: Avoid abbreviations unless they are well known.

2477–2490 ↗(On Diff #28147)

Nit: Indendation. Case labels should be at the same level as the switch.

2479 ↗(On Diff #28147)

Nit: Indentation of this particular line

2481 ↗(On Diff #28147)

This case is not reachable (it calls expandRotationImm() instead)

2486 ↗(On Diff #28147)

This case is not reachable (it calls expandRotationImm() instead)

2494–2496 ↗(On Diff #28147)

Nit: Don't use unnecessary braces.

2500 ↗(On Diff #28147)

Nit: Variables should start with a capital

2537–2538 ↗(On Diff #28147)

Nit: Indentation. Format it as per clang-format

2537–2597 ↗(On Diff #28147)

Most of the nits for expandRotation() also apply here.

2545–2546 ↗(On Diff #28147)

Nit: Avoid abbreviations unless they are well known

lib/Target/Mips/MipsInstrInfo.td
1557–1560 ↗(On Diff #28147)

Nit: Indentation.

1566–1569 ↗(On Diff #28147)

Nit: Indentation

test/MC/Mips/rotations.s
9 ↗(On Diff #28147)

Nit: Alignment of '# encoding'

likewise below.

This revision now requires changes to proceed.Jun 23 2015, 3:30 AM
obucina updated this revision to Diff 28241.Jun 23 2015, 7:33 AM
obucina retitled this revision from Expansion of ROL and ROR instructions to [mips] Expansion of ROL and ROR instructions.
obucina edited edge metadata.

New diff contains formatting fixes and renamed variables where suggested.

Daniel, my task was the expansion of these macros, by mips bugzilla report 723.

I believe that adding these as instructions on supported platforms is a whole different thing. For the start, we need information on which architectures these instructions exist and find their encodings. MIPS64 Instructions Set mentions only ROTR and ROTRV, and these two are already implemented.

I believe that this piece of code will not introduce any critical problems on platforms which support ROL/ROR instructions.

I am also preparing similar patch for DROL/DROR macros.

I believe it's closely related. On MIPS32r2 and later, ror/rol are aliases for rotr and rorv/rolv are aliases for rotrv/rotlv. Prior to MIPS32r2, they are macros that expand to equivalent code as per your patch.

Either way, you need to account for the case when the rotation immediate is zero.

obucina updated this revision to Diff 28786.Jun 30 2015, 8:25 AM
obucina retitled this revision from [mips] Expansion of ROL and ROR instructions to [mips] Expansion of ROL and ROR macros.
obucina edited edge metadata.

New diff contains ROL/ROR expansion for all 32rN and 64rN platforms, where these instructions are aliasses for ROTR and ROTRV.

obucina updated this revision to Diff 29255.Jul 8 2015, 5:31 AM

New diff contains expansions for ROL, ROR, DROL, DROR, for all cpus and test cases.

obucina updated this revision to Diff 29258.Jul 8 2015, 5:58 AM

Nit corrections + context

dsanders accepted this revision.Jul 9 2015, 3:47 AM
dsanders edited edge metadata.

LGTM with a few minor changes (mostly redundant predicates)

lib/Target/Mips/AsmParser/MipsAsmParser.cpp
2733 ↗(On Diff #29258)

The last three predicates are redundant. Predicates are cumulative so hasMips32r2() covers all of them.

2734–2738 ↗(On Diff #29258)

If this were:

unsigned TmpReg = DReg;
if (DReg == SReg) {
  TmpReg = getATReg(Inst.getLoc());
  if (!TmpReg)
    return true;
}

then you wouldn't need to conditionally select between ATReg and DReg later on lines 2744-2747 and 2757-2760. You could use TmpReg instead.

2778 ↗(On Diff #29258)

hasMips64() is redundant.

2844 ↗(On Diff #29258)

The last three are redundant.

2875 ↗(On Diff #29258)

hasMips64() is redundant

2947 ↗(On Diff #29258)

hasMips64r6() is redundant

2949–2953 ↗(On Diff #29258)

As noted in expandRotation(), assigning DReg to ATReg to a new variable (TmpReg?) would simplify lines 2959-2962 and 2972-2975.

3061 ↗(On Diff #29258)

hasMips64r6() is redundant

3084–3088 ↗(On Diff #29258)

Nit: Redundant braces

This revision is now accepted and ready to land.Jul 9 2015, 3:47 AM
obucina updated this revision to Diff 37738.Oct 19 2015, 5:02 AM
obucina edited edge metadata.

New diff contains nit fixes

obucina marked 21 inline comments as done.Oct 19 2015, 5:06 AM

New diff contains nit fixes

I'm not sure if phabricator is doing something strange here but I only see two of the nine nits fixed. The redundant braces and indentation nits are fixed but the rest don't seem to have been done.

obucina updated this revision to Diff 38927.EditedNov 2 2015, 8:36 AM

New diff contains nit corrections, usage of TmpReg as suggested, and necessary changes to be applicable to latest source code.

obucina updated this revision to Diff 40395.Nov 17 2015, 7:36 AM

New diff contains adaptations to the latest source code, using emit* functions for generating instructions.

This revision was automatically updated to reflect the committed changes.