This is an archive of the discontinued LLVM Phabricator instance.

[AVR] Fix an issue of writing 16-bit ports
ClosedPublic

Authored by benshi001 on Jan 14 2023, 12:45 AM.

Details

Summary

For 16-bit ports, the normal devices reqiure writing high byte first
and then low byte. But the XMEGA devices require the reverse order.

Fixes https://github.com/llvm/llvm-project/issues/58395

Diff Detail

Event Timeline

benshi001 created this revision.Jan 14 2023, 12:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2023, 12:45 AM
Herald added subscribers: Jim, hiraditya. · View Herald Transcript
benshi001 requested review of this revision.Jan 14 2023, 12:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2023, 12:45 AM
benshi001 added inline comments.Jan 14 2023, 1:07 AM
llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
1294

I like this form

Low bound <= variable && variable <= high bound.

Rather then

variable' <= Low bound` && variable <= high bound.

which looks like variable is in range [low, high].

This works for the out instruction, but what about a regular volatile store? I think it should be changed in the same way.

llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
1292–1293

I think this is usually done via subtarget flags, not by looking at e_flags. I couldn't easily find something similar in other targets. But this also works.

benshi001 updated this revision to Diff 490773.Jan 20 2023, 3:27 AM
benshi001 edited the summary of this revision. (Show Details)
benshi001 marked an inline comment as done.EditedJan 20 2023, 3:29 AM

This works for the out instruction, but what about a regular volatile store? I think it should be changed in the same way.

I have done for both OUTW and STSWKRr. Thanks!

llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
1292–1293

I have added a new target feature FeatureLowByteFirst and all XMEGA families contains this new feature.

benshi001 marked an inline comment as done.Jan 20 2023, 3:29 AM
benshi001 added inline comments.
llvm/lib/Target/AVR/AVRISelLowering.cpp
1114 ↗(On Diff #491038)

We disallow post increment store for 16-bit store on ordinary AVRs, while the XMEGA devices are still allowed.

All four pseudo instructions are modified : OUTW, STSWKRr, STDWPtrQRr, STWPtrRr.

Unfortunately many tests are affected, fortunately the only change is exchanging the order of a store pair. ^_^

We can see the full affection in the four pseudo instruction's .mir tests.

benshi001 added inline comments.Jan 20 2023, 11:14 PM
llvm/test/CodeGen/AVR/pseudo/STDWPtrQRr.mir
24 ↗(On Diff #491038)

The only difference between CHECK and CHECK-XMEGA is the order.

This revision is now accepted and ready to land.Apr 16 2023, 11:55 PM
This revision was automatically updated to reflect the committed changes.