[LLVMdev] Intrinsic cannot use illegal type

Duncan Sands baldrick at free.fr
Tue Mar 3 01:39:47 PST 2009


Hi Christian,

> I use a target specific Intrinsic that returns an illegal type.
> The idea is that this returned value shall be eliminated when the
> Intrinsic node is lowered to a target node.
> I realize that this is a rather late stage, since (at least)
> SelectionDAGLowering::visitTargetIntrinsic() requires legal types,
> and type legalization in general is also done before ISelLowering.

no, type legalization is done after everything has been lowered to
SelectionDAG nodes.  I'm not sure why visitTargetIntrinsic insists
that types must be legal.  If there is an illegal type there then
the type legalizer will complain later because it doesn't know how
to legalize it, that's all.  However the type legalizer (I'm talking
LLVM 2.5 here) allows targets to custom lower operations with illegal
types via hooks like ReplaceNodeResults.  So if you got rid of the
assertion in visitTargetIntrinsic and added some custom lowering
logic, then hopefully everything will work.

> The background is that the intrinsic returns a boolean value which
> is evaluated by a branch instruction of a (special) loop.

Why not have it return the boolean value in a legal type (eg: i32) and
follow it up with a truncate to turn it into an i1 for the benefit of
the branch?  That way you won't have to do any mucking around with the
type legalizer at all!

> The branch targets of this kind of loop are actually controlled and generated by  hardware. So in the end the intrinsic should become the branch instruction and the original branch should disappear.
> 
> Is there a way to make this intrinsic go through as it is until instruction lowering, and to avoid type legalization on it?

See above.

Ciao,

Duncan.



More information about the llvm-dev mailing list