This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] Allow scalable type dead store elimination
ClosedPublic

Authored by dtemirbulatov on Jan 19 2023, 3:21 AM.

Details

Summary

Allow scalable type dead store elimination in DAGCombine.

Diff Detail

Event Timeline

dtemirbulatov created this revision.Jan 19 2023, 3:21 AM
dtemirbulatov requested review of this revision.Jan 19 2023, 3:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 3:21 AM

Missed to update sve-redundant-store.ll test after change, fixed.

Fixed case where ST1 type size is bigger than in ST.

Matt added a subscriber: Matt.Jan 19 2023, 10:08 PM
sdesmalen added inline comments.Jan 20 2023, 1:22 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
19759–19764

This looks really confusing. You can use TypeSize::isKnownLE, which also returns true when comparing sizes with different scalable properties, e.g. sizeof(v8i32) <= sizeof(nxv8i32).
You'd just need to add an additional check that the base pointer is the same.

Ideally we'd extend BaseIndexOffset to handle scalable sizes as well, but that's quite a bit of work and may not be worth it.

dtemirbulatov retitled this revision from Allow scalable type dead store elimination in DAGCombine to [DAGCombine] Allow scalable type dead store elimination in DAGCombine.Jan 23 2023, 3:17 AM
dtemirbulatov retitled this revision from [DAGCombine] Allow scalable type dead store elimination in DAGCombine to [DAGCombine] Allow scalable type dead store elimination.

Dropped (STBitSize <= ChainBitSize) checks, it is not required as STBase.contains() ignores those to handle.

Addressed remakrs, using now TypeSize::isKnownLE.

sdesmalen added inline comments.Jan 30 2023, 8:09 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
19759–19764

For scalable vectors, can you avoid the call to STBase.contains() entirely and just check that the pointer is equal? Then you don't have to make the effort to compute the 'known' part of the STBitSize/ChainBitSize.

Use TypeSize::isKnownLE only if base pointers are equal.

sdesmalen added inline comments.Feb 3 2023, 1:20 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
19729

nit: unintended change?

19740–19744

I wonder if it's simpler to write this as follows:

if (ST->getMemoryVT().isScalableVector() ||
    ST1->getMemoryVT().isScalableVector()) {
  if (ST1->getBasePtr() == Ptr && TypeSize::isKnownLE(...))
    CombineTo(ST1, ST1->getChain());
} else {
  const BaseIndexOffset STBase = BaseIndexOffset::match(ST, DAG);
  const BaseIndexOffset ChainBase = BaseIndexOffset::match(ST1, DAG);
  if (STBase.contains(...))
    CombineTo(ST1, ST1->getChain());
}

That way the the logic between 'anything scalable' and everything else is clearly separated.

llvm/test/CodeGen/AArch64/sve-redundant-store.ll
21

This is missing some test cases, e.g.

  • One where both stores are scalable, and same size.
  • One where both stores are scalable, and second store is larger
  • One where both stores are scalable, and first store is larger (negative test)
dtemirbulatov marked 3 inline comments as done.

Addressed comments.

Fixed typo in test funtion name.

Thanks for adding the tests. Just two more minor comments and then I'm happy to accept.

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
19771–19773

Can you combine the two if-statements with an &&? That saves a level of indentation.

19779

You can remove the } else { here, which saves a level of indentation.

dtemirbulatov marked 2 inline comments as done.

Combined two ifs

Restoring the previous revision.

sdesmalen accepted this revision.Feb 7 2023, 7:08 AM

LGTM!

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
19771–19773

Sorry, I misread the indentation/curly braces here. The original version was fine, thanks for restoring it!

This revision is now accepted and ready to land.Feb 7 2023, 7:08 AM