This is an archive of the discontinued LLVM Phabricator instance.

[MSP430] Add support for MSP430X extended shift instructions
AbandonedPublic

Authored by jozefl on Sep 6 2021, 7:10 AM.

Details

Reviewers
asl
atrosinenko
Summary

There are two forms of MSP430X extended shift instructions:

  • "RxxM": RRAM, RRUM, RLAM, RRCM e.g. rram #3, r12
  • "RxxX": RRAX, RRUX, RLAX, RRCX e.g. rrax r12

RxxM shifts can shift by up to 4 bit positions, whilst RxxX shifts are
more expensive but can shift by up to 16 bit positions.

RxxX shifts do not have a shift count operand, instead the shift count
is set by using the "rpt" directive, which must precede the RxxX
instruction, if it is used at all. This directive sets bits in the
extension word of the 430X instruction, to indicate the number of times
the instruction should be repeated. As this is the first patch to add
430X extended instructions, the patch also adds initial support for the
430X extension word and the "rpt" directive.

RRCM and RRCX are not currently implemented as they are not required
when MSP430TargetLowering only lowers shifts with 8-bit or 16-bit
operands. They could be used in the future to improve the efficiency of
shifts for 32-bit or 64-bit operands.

In addition to the LLVM regression tests, I also ran the dg.exp, execute.exp,
and dg-torture.exp testsuites from GCC, using the MSP430 Binutils simulator.
The results for -mcpu=msp430{,x} were unchanged compared to the results for
-mcpu=msp430 without the patch, which gives some extra confidence that the
changes to how the shifts are lowered are valid.

If the patch is acceptable, I would appreciate it if someone would commit it
for me, as I do not have write access.

Diff Detail

Event Timeline

jozefl created this revision.Sep 6 2021, 7:10 AM
jozefl requested review of this revision.Sep 6 2021, 7:10 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 6 2021, 7:10 AM
jozefl updated this revision to Diff 371055.Sep 7 2021, 6:14 AM

Fixed one of the TODOs:

// TODO: When shifting by > 8 and opimizing for performance, we should use
// ShiftBy8, since it saves 6 cycles compared to using an RxxX insn.
// However, it adds an additional 2 word-sized instructions, so is bad for
// code size.

Added the appropriate tests.
Also changed some regular comments to Doxygen comments.

jozefl added inline comments.Sep 7 2021, 6:21 AM
llvm/lib/Target/MSP430/MSP430ISelLowering.cpp
1106–1107

There are some pre-existing missed optimizations when shifting memory operands, so I'm going to fix them along with this TODO in a separate commit.

Pinging for review.

Thanks,
Jozef

asl added a comment.Sep 28 2021, 10:58 AM

Will it be possible to split this patch into 3:

  1. Addition of rpt
  2. Addition of shift instructions
  3. Codegen

Thanks!

Will it be possible to split this patch into 3:

  1. Addition of rpt
  2. Addition of shift instructions
  3. Codegen

Thanks!

Ok, I've split the patch into these three revisions: https://reviews.llvm.org/D110723 https://reviews.llvm.org/D110724 https://reviews.llvm.org/D110725
I diffed the 3 new combined patches against this patch and there are only minor NFC differences from things that I fixed up in the new patches.

Thanks,
Jozef