Promoting i1 to i32 does not work...

Hi there,

I'm having a hard time with promoting operands from i1 to i32 in my
backend...
I have to register classes, VTs are i1 and i32. The i1 registers are
only for predication and conditional jumps, so I want to use them with
brcond, setcc.
There are no instructions to directly load a value in an i1 register or
to copy between i1 and i32, so I need the DAG Legalizing Pass to not
generate any nodes with i1 operands. That's where the trouble starts.
Occasionally, there are setcc's with i1 operands being legalized for any
reason I don't get.
I tried setOperationAction(ISD::SETCC, i1, Promote), but the i1 operands
didn't get promoted...I looked through the dump and it seems the i1
operands will be inserted after Initial selection DAG building, but
before Type-Legalization. So I wonder why they don't get promoted by
the Legalization Pass?!

I attached the shortened isel-dump, so if anyone could have a short look
on that I would be very thankful!

Jan

dump (6.81 KB)

Hi there,

I'm having a hard time with promoting operands from i1 to i32 in my
backend...
I have to register classes, VTs are i1 and i32. The i1 registers are
only for predication and conditional jumps, so I want to use them with
brcond, setcc.
There are no instructions to directly load a value in an i1 register or
to copy between i1 and i32, so I need the DAG Legalizing Pass to not
generate any nodes with i1 operands. That's where the trouble starts.
Occasionally, there are setcc's with i1 operands being legalized for any
reason I don't get.
I tried setOperationAction(ISD::SETCC, i1, Promote), but the i1 operands
didn't get promoted...I looked through the dump and it seems the i1
operands will be inserted after Initial selection DAG building, but
before Type-Legalization. So I wonder why they don't get promoted by
the Legalization Pass?!

The problem with this program is that
i32 = and x, 1 is being lowered to i1 = truncate x by the DAGCombiner.

The legalizer is correctly promoting the SETCC arguments to i32, but the
DAGCombiner is undoing this promotion, because it sees
i32 = zero_extend (truncate x) and optimizes out the zero_extend.

I think if you do setOperationAction(ISD::TRUNCATE, MVT::i1, Expand),
it should fix them problem.

Note that if you have added an i1 register class using addRegisterClass(),
the SelectionDAG will assume that all (with a few exceptions) i1
operations are legal unless you tell it otherwise.

-Tom