Expanding SDNodes

Hello all,

I’ve been working on writing a backend, I was testing zext, and during the first run of combining llc does the following thing:

=== zext
Creating new node: t3: i16 = truncate t2
Creating new node: t5: ch = CopyToReg t0, Register:i32 %vreg1, t2
Creating new node: t6: i32 = zero_extend t3
Creating new node: t9: ch = MyArchISD::RET_FLAG t8, Register:i32 %R0, t8:1
Initial selection DAG: BB#0 ‘zext:entry’
SelectionDAG has 10 nodes:
t0: ch = EntryToken
t2: i32,ch = CopyFromReg t0, Register:i32 %vreg0
t5: ch = CopyToReg t0, Register:i32 %vreg1, t2
t3: i16 = truncate t2
t6: i32 = zero_extend t3
t8: ch,glue = CopyToReg t5, Register:i32 %R0, t6
t9: ch =MyArchISD::RET_FLAG t8, Register:i32 %R0, t8:1

Combining: t9: ch =MyArchISD::RET_FLAG t8, Register:i32 %R0, t8:1

Combining: t8: ch,glue = CopyToReg t5, Register:i32 %R0, t6

Combining: t7: i32 = Register %R0

Combining: t6: i32 = zero_extend t3
Creating constant: t10: i32 = Constant<65535>
Creating new node: t11: i32 = and t2, Constant:i32<65535>
… into: t11: i32 = and t2, Constant:i32<65535>

I was wondering if there is a way to expand the t6 node to “zext t3” so it won’t combine?
(Maybe defining some pattern on my backend’s tablegen or something like that)
Thanks,
Liad.

The DAG combiner will expand zero-extends into ands, and in your selection patterns you can simply match a corresponding and with the bitmask instead of a zext. You can even write a PatFrag to serve as a macro for that.
Another option is that you can lower zero-extend to a custom operation for your target. DAG combiner won't do anything with it, and then you can match it directly in the patterns.

-Krzysztof