[llvm-dev] Return value from TargetLowering::LowerOperation?

Tom Stellard via llvm-dev llvm-dev at lists.llvm.org
Fri Jan 22 08:02:17 PST 2016


On Fri, Jan 22, 2016 at 01:58:49PM +0100, Mikael Holmén via llvm-dev wrote:
> Hi,
> 
> I'm a litle bit puzzled by the TargetLowering::LowerOperation function, 
> and what different callers of this function assumes about the returned 
> value.
> 
SelectionDAGLegalize::LegalizeOp() is your best reference for this.

> In several places it seems like it is assumed that LowerOperation can 
> return three kinds of values:
> * Something completely new.
> * SDValue()

This tells the legalizer to treat the node as if it were marked Expand.
For loads and stores it tells the legalizer to treat the node as if
it were marked Promote.

> * The same SDValue as LowerOperation was called on.

This tells the legalizer that the input node is legal.

> 
> However in some places, e.g. in TargetLowering::LowerOperationWrapper, 
> it seems like it is assumed only the first two of the above cases can 
> happen because there we do:
> 
>    SDValue Res = LowerOperation(SDValue(N, 0), DAG);
>    if (Res.getNode())
>      Results.push_back(Res);
> 
> So, when LowerOperationWrapper is called from 
> DAGTypeLegalizer::CustomLowerNode, and my target's LowerOperation 
> returns the same SDValue as it was called on since we don't want to do 
> anything special with this particular SDValue, then we get an assert 
> "Potential legalization loop!" when DAGTypeLegalizer::CustomLowerNode 
> tries to replace the SDValue with itself.
> 

I think this error can only happen during type legalization, so my guess
is that you are returning a node that has an illegal type.  Can you
provide more information about the node this is failing with?

-Tom

> So in some cases it's ok for LowerOperation to return the same SDValue 
> it was called on, and sometimes it's not?
> 
> Can anyone shed some light on this?
> 




> Thanks,
> Mikael
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev


More information about the llvm-dev mailing list