This is an archive of the discontinued LLVM Phabricator instance.

[AVR] Optimize 32-bit shifts: shift by 4 bits
ClosedPublic

Authored by aykevl on Dec 22 2022, 11:18 AM.

Details

Summary

This uses a complicated shift sequence that avr-gcc also uses, but
extended to work over any number of bytes and in both directions
(logical shift left and logical shift right). Unfortunately it can't be
used for an arithmetic shift right: I've tried to come up with a
sequence but couldn't.

Diff Detail

Event Timeline

aykevl created this revision.Dec 22 2022, 11:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 22 2022, 11:18 AM
Herald added subscribers: Jim, hiraditya. · View Herald Transcript
aykevl requested review of this revision.Dec 22 2022, 11:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 22 2022, 11:18 AM
aykevl updated this revision to Diff 485835.Jan 1 2023, 6:11 PM
  • rebase
benshi001 added inline comments.Jan 2 2023, 7:14 PM
llvm/lib/Target/AVR/AVRISelLowering.cpp
1934

I have two concerns here:

  1. It would be better to show a 4-byte shift example, other than a 2-byte one, since you are optimizating the previous one.
  1. Your inline comments ; shift r1 and ; shift r0 are incorrect, actually the r1 is also modified by the last instruction. I think you only give the direct instruction sequence is OK enough.
1941

Use I than 'i' to be conform with other loops in this function.

1946

I think it would be better to change to if (i > 0).

1957

I think it would be better to change to if (i > 0).

1963

How about

size_t PrevIdx = ShiftLeft ? Idx - 1 : Idx + 1;
Regs[PrevIdx] = std::pair(R, 0);
llvm/test/CodeGen/AVR/shift32.ll
168

This looks really great!

benshi001 requested changes to this revision.Jan 2 2023, 7:18 PM
This revision now requires changes to proceed.Jan 2 2023, 7:18 PM
aykevl updated this revision to Diff 486960.Jan 6 2023, 12:19 PM
aykevl set the repository for this revision to rG LLVM Github Monorepo.
  • apply review feedback
llvm/lib/Target/AVR/AVRISelLowering.cpp
1934

Yes, this isn't very clear. I have updated the explanation in a way that better explains what the code does.

1946

Hmm, somehow I missed this while rebasing. Fixed.

1957

Fixed.

1963

Not sure which one is clearer but seems good to me. Change applied.

benshi001 accepted this revision.Jan 6 2023, 7:10 PM
This revision is now accepted and ready to land.Jan 6 2023, 7:10 PM
This revision was automatically updated to reflect the committed changes.