[RFC] PatternMatch for SelectionDAG
Nadav Rotem
nrotem at apple.com
Sat Jul 20 22:24:16 PDT 2013
David,
I am really happy to see that you are working on this. As part of the discussions on replacing SelectionDAG with something new, a few people mentioned that it would be much easier to migrate to a new infrastructure if the patterns were written in patterns such as the ones that you are proposing. I like your approach. I look forward to seeing the complete patch.
Thanks,
Nadav
On Jul 20, 2013, at 6:48 PM, David Majnemer <david.majnemer at gmail.com> wrote:
> I'd like to propose a PatternMatch-like interface for SelectionDAG.
>
> I have a simple implementation attached, it matches on SDValue types and provides a convenience overload for SDNodes.
>
> Currently, it uses similar names to PattternMatch.h (match, m_And, etc.).
> I don't really care about the names but I figured to start with something familiar. They shouldn't conflict because they would both exist in their own namespaces.
>
> The effect is pretty nice on some DAGCombiner code:
>
> // (or (and X, C1), (and Y, C2)) -> (and (or X, Y), C3) if possible.
> if (N0.getOpcode() == ISD::AND &&
> N1.getOpcode() == ISD::AND &&
> N0.getOperand(1).getOpcode() == ISD::Constant &&
> N1.getOperand(1).getOpcode() == ISD::Constant &&
> // Don't increase # computations.
> (N0.getNode()->hasOneUse() || N1.getNode()->hasOneUse())) {
> const APInt &LHSMask =
> cast<ConstantSDNode>(N0.getOperand(1))->getAPIntValue();
> const APInt &RHSMask =
> cast<ConstantSDNode>(N1.getOperand(1))->getAPIntValue();
>
> becomes:
> const APInt *LHSMask, *RHSMask;
> if (match(N0, m_And(m_Value(), m_APInt(LHSMask))) &&
> match(N1, m_And(m_Value(), m_APInt(RHSMask))) &&
> // Don't increase # computations.
> (match(N0, m_OneUse()) || match(N1, m_OneUse()))) {
>
> Note that the attached implementation is pretty incomplete, I just wanted a proof of concept before I run off and flesh it out further.
>
> Thanks
>
> --
> David Majnemer
> <ns.h>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130720/8d5b6283/attachment.html>
More information about the llvm-commits
mailing list