This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][LoadStoreOptimizer] Ignore undef registers when checking rename register used between paired instructions.
ClosedPublic

Authored by huihuiz on Feb 8 2022, 5:25 PM.

Details

Summary

The content of undef registers are not used in meaningful ways, when checking
if a rename register is used between paired instructions we should ignore
undef registers.

Diff Detail

Event Timeline

huihuiz created this revision.Feb 8 2022, 5:25 PM
huihuiz requested review of this revision.Feb 8 2022, 5:25 PM

Take test mir attached test/CodeGen/AArch64/stp-opt-with-renaming-crash.mir
run with llc -run-pass=aarch64-ldst-opt -mtriple=aarch64 -verify-machineinstrs

Then you will see assertion
"Rename register used between paired instruction, trashing the content".

Although we don't really care trashing content of an undef, but should we exclude undef when checking for overlap ?

#if !defined(NDEBUG)
    // Make sure the register used for renaming is not used between the paired
    // instructions. That would trash the content before the new paired
    // instruction.
    for (auto &MI :
         iterator_range<MachineInstrBundleIterator<llvm::MachineInstr>>(
             std::next(I), std::next(Paired)))
      assert(all_of(MI.operands(),
                    [this, &RenameReg](const MachineOperand &MOP) {
                      return !MOP.isReg() || MOP.isDebug() || !MOP.getReg() ||
                             **MOP.isUndef() ||**
                             !TRI->regsOverlap(MOP.getReg(), *RenameReg);
                    }) &&
             "Rename register used between paired instruction, trashing the "
             "content");
#endif

Probably the code printing the "Rename register used between paired instruction" diagnostic should ignore undef use; such uses don't use the value in any meaningful way.

For reference, the code in LiveRegUnits considers isDef() a write, and readsReg() a read.

huihuiz updated this revision to Diff 407271.Feb 9 2022, 1:28 PM
huihuiz retitled this revision from [AArch64][LoadStoreOptimizer] Make sure physical registers used by renamable undef are not picked as register to rename. to [AArch64][LoadStoreOptimizer] Ignore undef registers when checking rename register used between paired instructions..
huihuiz edited the summary of this revision. (Show Details)

Thanks Eli for the feedbacks!
Exclude undef from overlap diagnosis.

efriedma accepted this revision.Feb 9 2022, 1:36 PM

LGTM

This revision is now accepted and ready to land.Feb 9 2022, 1:36 PM
This revision was landed with ongoing or failed builds.Feb 10 2022, 10:22 AM
This revision was automatically updated to reflect the committed changes.

Thanks for fixing that!

llvm/test/CodeGen/AArch64/stp-opt-with-renaming-undef-assert.mir
40 ↗(On Diff #407598)

Are those needed or could be dropped?

huihuiz marked an inline comment as done.Feb 10 2022, 12:43 PM

Thanks @fhahn , stack accesses are not needed. I just clean them in https://reviews.llvm.org/rG19302cd7a449