[RFC] PatternMatch for SelectionDAG

David Majnemer david.majnemer at gmail.com
Sat Jul 20 18:48:43 PDT 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130720/5cd7a790/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ns.h
Type: text/x-chdr
Size: 2938 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130720/5cd7a790/attachment.h>


More information about the llvm-commits mailing list