This is an archive of the discontinued LLVM Phabricator instance.

[SDAG] neg x with only low bit demanded is x
ClosedPublic

Authored by reames on Dec 19 2022, 10:53 AM.

Details

Summary

We have a version of this transform in InstCombine, but surprisingly not in SDAG.

Even more surprisingly, this benefits RISCV, but no other target. This was surprising enough I double checked my build configuration to make sure all targets were enabled; they appear to be.

Diff Detail

Event Timeline

reames created this revision.Dec 19 2022, 10:53 AM
reames requested review of this revision.Dec 19 2022, 10:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2022, 10:53 AM
reames retitled this revision from [SDAG] neg x with one demanded bit is x to [SDAG] neg x with only low bit demanded is x.Dec 19 2022, 11:02 AM
craig.topper added inline comments.Dec 19 2022, 11:53 AM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
2618

ISD::MUL has a fallthrough into this block. I don't think this is correct for it.

asb added a comment.Dec 19 2022, 12:29 PM

Looks good from my perspective once the mul fallthrough is addressed (good catch Craig!).

reames added inline comments.Dec 19 2022, 2:36 PM
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
2618

Good catch, thank you!

reames updated this revision to Diff 484083.Dec 19 2022, 2:45 PM
This revision is now accepted and ready to land.Dec 19 2022, 2:55 PM
This revision was landed with ongoing or failed builds.Dec 19 2022, 3:26 PM
This revision was automatically updated to reflect the committed changes.