This is an archive of the discontinued LLVM Phabricator instance.

[SelectionDAG] Improve `isKnownToBeAPowerOfTwo`
ClosedPublic

Authored by goldstein.w.n on Aug 1 2023, 12:35 AM.

Details

Summary

Add additional cases for:
select, vselect, {u,s}{min,max}, and, casts, rotl, rotr

And improve handling of constants and shifts.

Diff Detail

Event Timeline

goldstein.w.n created this revision.Aug 1 2023, 12:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2023, 12:35 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
goldstein.w.n requested review of this revision.Aug 1 2023, 12:35 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2023, 12:35 AM
arsenm added a subscriber: arsenm.Aug 1 2023, 3:56 PM
arsenm added inline comments.
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4051

Looking through ANY_EXTEND is probably broken

4103–4104

try RHS first

RKSimon added inline comments.Aug 2 2023, 3:34 AM
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4106

Add comments describing the and(x,neg(x)) pattern

4112

Do you need to use matchUnaryPredicate or could you just call isNullOrNullSplat ?

RKSimon added inline comments.Aug 2 2023, 3:39 AM
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
4060

We can't safely use ANY_EXTEND, afaict you just need this:

while (Val.getOpcode() == ISD::ZERO_EXTEND)
  Val = Val.getOperand(0);
goldstein.w.n marked 5 inline comments as done.Aug 2 2023, 9:32 AM

Remove any-extend, comment and case.

RKSimon added inline comments.Aug 3 2023, 2:18 AM
llvm/test/CodeGen/X86/known-pow2.ll
626

Any luck in triaging this?

goldstein.w.n added inline comments.Aug 3 2023, 10:19 AM
llvm/test/CodeGen/X86/known-pow2.ll
626

I think for vecs (on X86) doing X & Y != 0 is just not preferable to X & Y == Y.
I fixed this up in D157014 and changed the rest of the vselect tests to use ne so we can properly see the change.

RKSimon accepted this revision.Aug 4 2023, 6:07 AM

LGTM

This revision is now accepted and ready to land.Aug 4 2023, 6:07 AM
This revision was landed with ongoing or failed builds.Aug 15 2023, 11:59 PM
This revision was automatically updated to reflect the committed changes.