This is an archive of the discontinued LLVM Phabricator instance.

[DAG] Fold (sra (or (shl x, c1), (shl y, c2)), c1) -> (sext_inreg (or x, (shl y,c2-c1)) iff c2 >= c1
AbandonedPublic

Authored by RKSimon on Oct 17 2022, 7:22 AM.

Details

Summary

Addresses the AMDGPU regression identified in D136042 where we were losing signed BFE patterns after sinking shifts behind logic ops.

Diff Detail

Event Timeline

RKSimon created this revision.Oct 17 2022, 7:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 17 2022, 7:22 AM
RKSimon requested review of this revision.Oct 17 2022, 7:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 17 2022, 7:22 AM
foad added inline comments.Oct 18 2022, 6:05 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
9456–9457

Seems like an odd mix of getAPIntValue vs getZExtValue.

9464

How does this work? Is it checking legality of SIGN_EXTEND_INREG with the specified inner type, irrespective of the outer type?

RKSimon added inline comments.Oct 18 2022, 6:52 AM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
9456–9457

Yeah, its to account for the fact that the inner shift amount types might not match N1 (or might be out of bounds) - its messy I agree but adding all the type/inrange matching was worse :(

9464

This was copied from the (sra (shl x, c1), c1) -> sext_inreg fold immediately above - I'll see if I can improve it.

foad accepted this revision.Oct 18 2022, 7:28 AM

LGTM either with or without improving the legality check for SIGN_EXTEND_INREG.

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
9456–9457

Oh I see. I guess using getZExtValue in both places would have been less surprising.

This revision is now accepted and ready to land.Oct 18 2022, 7:28 AM
This revision was landed with ongoing or failed builds.Oct 19 2022, 3:19 AM
This revision was automatically updated to reflect the committed changes.
RKSimon reopened this revision.Oct 19 2022, 6:37 AM
This revision is now accepted and ready to land.Oct 19 2022, 6:37 AM
RKSimon abandoned this revision.Oct 19 2022, 6:37 AM