This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Select the D-Form load if we know its offset meets the requirement
ClosedPublic

Authored by steven.zhang on Dec 11 2020, 3:00 AM.

Details

Summary

I happens to see this issue and this is a simple patch to fix the issue I saw.

The LD/STD likewise instruction are selected only when the alignment in the load/store >= 4 to deal with the case that the offset might not be known(i.e. relocations), which is done by this patch.

commit b09680b0f793254c7985dd42f3ef8ea56a388c10
Author: Hal Finkel <hfinkel@anl.gov>
Date:   Mon Mar 18 23:00:58 2013 +0000

    Fix PPC unaligned 64-bit loads and stores

    PPC64 supports unaligned loads and stores of 64-bit values, but
    in order to use the r+i forms, the offset must be a multiple of 4.
    Unfortunately, this cannot always be determined by examining the
    immediate itself because it might be available only via a TOC entry.

    In order to get around this issue, we additionally predicate the
    selection of the r+i form on the alignment of the load or store
    (forcing it to be at least 4 in order to select the r+i form).

That means we have to select the X-Form load for %0 = load i64, i64* %arrayidx, align 2 In fact, we can still select the D-Form load if the offset is known. So, we only query the load/store alignment when we don't know if the offset is a multiple of 4.

Though we have the peephole to transform the X-Form load/store to D-Form load/store, and that's why we didn't see too much assembly changed. But it exposes more opportunities for us if we can select it as D-Form as early as possible as some optimization only works for D-Form load.

Diff Detail

Event Timeline

steven.zhang created this revision.Dec 11 2020, 3:00 AM
steven.zhang requested review of this revision.Dec 11 2020, 3:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 11 2020, 3:00 AM
nemanjai accepted this revision.Dec 11 2020, 6:49 AM

LGTM.
Most of this will be going away soon since we're refactoring how we select memory access instructions, but that's fine.

This revision is now accepted and ready to land.Dec 11 2020, 6:49 AM
jsji added a subscriber: jsji.Dec 11 2020, 7:20 AM

Although a refactor is coming, we should still avoid introducing more confusion if possible.
Please update the name and comments also. Thanks.

llvm/lib/Target/PowerPC/PPCInstrInfo.td
498–502

Comments also needs update.

507–508

The fix has changed the semantic of this PatFrag, so I think we should also rename the PatFrag to avoid confusion.

steven.zhang added inline comments.Dec 14 2020, 12:08 AM
llvm/lib/Target/PowerPC/PPCInstrInfo.td
498–502

I will update it.

507–508

The semantics now is quite the same as quadwOffsetLoad except that we are checking more on the ld/st alignment. So, how about the dwOffsetLoad/nonDwOffsetLoad ? The alignment is hidden inside the interface as it seems to be some workround to me for those TOC relocation offset.

jsji added inline comments.Dec 15 2020, 5:58 PM
llvm/lib/Target/PowerPC/PPCInstrInfo.td
507–508

How about DSFormLoad/DSFormStore, nonDSFormLoad/nonDSFormStore or XFormLoad/XFormStore?

Address comments.

llvm/lib/Target/PowerPC/PPCInstrInfo.td
507–508

I will use the NonDSFormLoad/NonDSFormStore as non ds form doesn't mean it is x form.