This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] Mask doesn't have to be (EltSize - 1) exactly when combining rotation
ClosedPublic

Authored by pcwang-thead on Jul 21 2022, 4:47 AM.

Details

Summary

I think what we need is the least Log2(EltSize) significant bits are known to be ones.

Diff Detail

Event Timeline

pcwang-thead requested review of this revision.Jul 21 2022, 4:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 21 2022, 4:48 AM

Rebase on precommit test.

RKSimon added inline comments.Jul 21 2022, 5:04 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7315–7316

It might be worthwhile to replace the ISD::AND case with SimplifyMultipleUseDemandedBits:

if (IsRotate && isPowerOf2_64(EltSize)) {
  unsigned Bits = Log2_64(EltSize);
  APInt DemandedBits = APInt::getLowBitsSet(EltSize, Bits);
  if (SDValue Inner = SimplifyMultipleUseDemandedBits(Neg, DemandedBits, DAG)) {
    Neg = Inner;
    MaskLoBits = Bits;
  }
}

Address comment.

pcwang-thead marked an inline comment as done.Jul 21 2022, 5:55 AM
pcwang-thead added inline comments.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7315–7316

Thanks! I think it makes sense!

pcwang-thead retitled this revision from [DAGCombine] Mask don't have to be (EltSize - 1) exactly when combining rotation to [DAGCombine] Mask doesn't have to be (EltSize - 1) exactly when combining rotation.Jul 21 2022, 5:56 AM
RKSimon accepted this revision.Jul 22 2022, 2:49 AM

LGTM

This revision is now accepted and ready to land.Jul 22 2022, 2:49 AM
pcwang-thead marked an inline comment as done.

Rebased on new tests.

Any thoughts about comments? I think they may be not matched with implementation now. @RKSimon

Any thoughts about comments? I think they may be not matched with implementation now. @RKSimon

You mean the pseudo-code that refers to 'Neg & (EltSize - 1)' etc?

Any thoughts about comments? I think they may be not matched with implementation now. @RKSimon

You mean the pseudo-code that refers to 'Neg & (EltSize - 1)' etc?

Yes. Is it OK to keep the same?

How about this?

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7311

// This allows us to peek through any operations that only the affect Mask's un-demanded bits.

Update comments.

pcwang-thead marked an inline comment as done.Jul 26 2022, 12:05 AM
pcwang-thead added inline comments.
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7311

Make sense to me. Thanks!

This revision was landed with ongoing or failed builds.Jul 26 2022, 6:15 AM
This revision was automatically updated to reflect the committed changes.
pcwang-thead marked an inline comment as done.

This seems to be hitting assertions when compiling BoringSSL:
https://luci-milo.appspot.com/ui/p/fuchsia/builders/ci/clang_toolchain.ci.core.x64-release/b8807566603550542609/overview

Haven't conclusively proven that it's this change, but it's the only one in the blamelist that could affect X86 ISel.

This seems to be hitting assertions when compiling BoringSSL:
https://luci-milo.appspot.com/ui/p/fuchsia/builders/ci/clang_toolchain.ci.core.x64-release/b8807566603550542609/overview

Haven't conclusively proven that it's this change, but it's the only one in the blamelist that could affect X86 ISel.

More likely its exposed something - demanded bits tends to do that. Any chance you can send us the IR file? Or even just the pre-processed source.

RKSimon added inline comments.Jul 26 2022, 9:36 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
7318

I'm only guessing but you might need to use Neg.getScalarValueSizeInBits instead of EltSize - it might be that the shift amount type doesn't match the result type

7338

Pos.getScalarValueSizeInBits instead of EltSize

Thanks, looks like that did the trick.

Thanks for the fix! :-) @RKSimon