This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombine] Move the remaining X86 funnel shift patterns to DAGCombine
ClosedPublic

Authored by RKSimon on Apr 27 2020, 8:37 AM.

Details

Summary

X86 matches several 'shift+xor' funnel shift patterns:

fold (or (srl (srl x1, 1), (xor y, 31)), (shl x0, y))  -> (fshl x0, x1, y)
fold (or (shl (shl x0, 1), (xor y, 31)), (srl x1, y))  -> (fshr x0, x1, y)
fold (or (shl (add x0, x0), (xor y, 31)), (srl x1, y)) -> (fshr x0, x1, y)

These patterns are also what we end up with the proposed expansion changes in D77301.

This patch moves these to DAGCombine's generic MatchFunnelPosNeg.

All existing X86 test cases still pass, and we just have a small codegen change in pr32282.ll.

Diff Detail

Event Timeline

RKSimon created this revision.Apr 27 2020, 8:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2020, 8:37 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
spatel accepted this revision.Apr 29 2020, 9:14 AM

LGTM

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

I see that this is just converting the existing code, but this would always get converted to 'shift-left' in IR. Should we add that canonicalization to SDAG as well?

This revision is now accepted and ready to land.Apr 29 2020, 9:14 AM
RKSimon added inline comments.Apr 29 2020, 2:09 PM
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
6387

I think so, the rotation/byteswap matching code has to match both patterns in several places - and there's probably more that I've missed. I'm not sure if we have anything that is relying on ADD(x,x) though. I'll add a TODO to this and do some tests.