This is an archive of the discontinued LLVM Phabricator instance.

[SDAG] add demanded bits transform for bswap
ClosedPublic

Authored by spatel on Jan 17 2022, 12:01 PM.

Details

Summary

A possible codegen regression for PowerPC is noted in D117406 because we don't recognize a pattern that demands a single byte from a bswap.

I was wondering if we have that fold in IR, and it has existed there since close to the beginning of LLVM:
https://github.com/llvm/llvm-project/blame/main/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp#L794
...so this patch copies that code as much as possible and adapts it for SDAG.

The test for PowerPC that would change in D117406 is over-reduced with undefs, so I recreated it for AArch64 and x86 by passing in pointer args and renamed the values to make the logic clearer.

Diff Detail

Event Timeline

spatel created this revision.Jan 17 2022, 12:01 PM
spatel requested review of this revision.Jan 17 2022, 12:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 17 2022, 12:01 PM

powerpc test missing?

The test for PowerPC is over-reduced with undefs, so I made it valid again by passing in pointer args and renamed the values to make the logic clearer.

Is that part of a different patch or a pre-commit? There's no PowerPC test change in this patch.

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
1828

Why can't we use getShiftAmountTy always? I fixed the problem that it only works for legal types a few months ago.

spatel edited the summary of this revision. (Show Details)Jan 17 2022, 12:40 PM

powerpc test missing?

Sorry, the description wasn't clear (updated text). The PPC test is in D117406 but not affected here.

spatel planned changes to this revision.Jan 17 2022, 1:13 PM
spatel marked an inline comment as done.

Just noticed that MSP430 can infinite loop because it doesn't have legal shifts. This needs a legal op check to be safe.

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
1828

Ah, didn't realize that. I copied this from the case ISD::SIGN_EXTEND_INREG block (line 1876). I can update that as a cleanup.

spatel updated this revision to Diff 400637.Jan 17 2022, 1:59 PM
spatel marked an inline comment as done.

Patch updated:

  1. Removed unnecessary shift amount type-checks.
  2. Added shift operation legality check (MSP430 tests fail without that).
This revision is now accepted and ready to land.Jan 17 2022, 2:31 PM
This revision was landed with ongoing or failed builds.Jan 17 2022, 3:34 PM
This revision was automatically updated to reflect the committed changes.