[RFC] PatternMatch for SelectionDAG
Christian König
deathsimple at vodafone.de
Sun Jul 21 10:00:38 PDT 2013
Am 21.07.2013 07:24, schrieb Nadav Rotem:
> 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.
>
Completely agreeing on this, I was already wondering why matching
SelectionDAG nodes looked so conventional while matching LLVM IR has a
rather elegant solution.
Please leave me a notice if you have a complete solution,
Christian.
>>
>> 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 <mailto:llvm-commits at cs.uiuc.edu>
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
>
> _______________________________________________
> 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/20130721/3572b8e4/attachment.html>
More information about the llvm-commits
mailing list