Re-using a node in a DAG output pattern in TableGen

Hello,

I currently have an instruction selection pattern that looks like this :

def : Pat<myinputop type:$v0 type:$v1,

(COMPNHQ
(ADDHQrr

(SLLHQSri $v0, 8),

(SLLHQSri $v1, 8),

),

(SLLHQSri $v0, 8),

comparison_ltu

)>;

This output pattern is supposed to be a DAG: the node (SLLHQSri $v0, 8) is used two times.

Experimentally, TableGen seems to recognize it as such (the node (SLLHQSri $v0, 8) will not be duplicated).

I am wondering if there is a way to avoid having to repeat (SLLHQSri $v0, 8) in the syntax of TableGen, something like:

def : Pat<inputpattern type:$v0 type:$v1,
(COMPNHQ
(ADDHQrr
(SLLHQSri $v0, 8):$myvar,
(SLLHQSri $v1, 8),
),
$myvar,
comparison_ltu
)>;

If I try this, I get the error “Node ‘myvar’ in output pattern but not input pattern”.

Does anyone know if there is a way to name nodes from an output pattern to produce a non-tree output DAG?

Do you know of any existing pattern featuring output DAG that are not trees?

Thanks

You might give OutPatFrag a try:

// OutPatFrag is a pattern fragment that is used as part of an output pattern
// (not an input pattern). These do not have predicates or transforms, but are
// used to avoid repeated subexpressions in output patterns.
class OutPatFrag<dag ops, dag frag>
: PatFrag<ops, frag, [{}], NOOP_SDNodeXForm>;

Thank you!

Cyril Six
Compiler Engineer • Kalray
Phone:
csix@kalrayinc.comwww.kalrayinc.com


Kalray logo

Please consider the environment before printing this e-mail.
This message contains information that may be privileged or confidential and is the property of Kalray S.A. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.