[PATCH 2/4] R600: Change UDIV/UREM to UDIVREM when legalizing types

Jan Vesely jan.vesely at rutgers.edu
Fri Apr 25 12:58:44 PDT 2014


On Fri, 2014-04-25 at 15:21 -0400, Tom Stellard wrote:
> On Fri, Apr 25, 2014 at 03:08:36PM -0400, Jan Vesely wrote:
> > When legalizing ops, with UDIV/UREM set to expand, they automatically
> > expand to UDIVREM (if legal or custom).
> > We need to do this manually for legalize types.
> > 
> 
> Are you sure this is necessary?  Looking at the code in LegalizeDAG.cpp
> UDIV and UREM should be automatically expanded ad long as UDIVREM is
> Legal or Custom.

The code in ExpandNode() is only called from LegalizeOP() and not used
for legalizing types.

DAGTypeLegalizer::ExpandIntegerResult (LegalizeIntegerTypes.cpp)
calls DAGTypeLegalizer::ExpandIntres_UDIV (same file) and does not
consider UDIVREM and only makes library call.

It should be possible to modify ExpandIntegerResult to handle UDIVREM
and use it instead of making library calls.

regards,
Jan

> 
> -Tom
> 
> > Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> > ---
> >  lib/Target/R600/AMDGPUISelLowering.cpp | 22 +++++++++++++++++++++-
> >  1 file changed, 21 insertions(+), 1 deletion(-)
> > 
> > diff --git a/lib/Target/R600/AMDGPUISelLowering.cpp b/lib/Target/R600/AMDGPUISelLowering.cpp
> > index c56fd3f..01d1eaf 100644
> > --- a/lib/Target/R600/AMDGPUISelLowering.cpp
> > +++ b/lib/Target/R600/AMDGPUISelLowering.cpp
> > @@ -202,8 +202,11 @@ AMDGPUTargetLowering::AMDGPUTargetLowering(TargetMachine &TM) :
> >    setOperationAction(ISD::MUL, MVT::i64, Expand);
> >  
> >    setOperationAction(ISD::UDIV, MVT::i32, Expand);
> > +  setOperationAction(ISD::UDIV, MVT::i64, Custom);
> >    setOperationAction(ISD::UDIVREM, MVT::i32, Custom);
> > +  setOperationAction(ISD::UDIVREM, MVT::i64, Custom);
> >    setOperationAction(ISD::UREM, MVT::i32, Expand);
> > +  setOperationAction(ISD::UREM, MVT::i64, Custom);
> >    setOperationAction(ISD::VSELECT, MVT::v2f32, Expand);
> >    setOperationAction(ISD::VSELECT, MVT::v4f32, Expand);
> >  
> > @@ -408,7 +411,24 @@ void AMDGPUTargetLowering::ReplaceNodeResults(SDNode *N,
> >      // ReplaceNodeResults to sext_in_reg to an illegal type, so we'll just do
> >      // nothing here and let the illegal result integer be handled normally.
> >      return;
> > -
> > +  case ISD::UDIV: {
> > +    SDValue Op = SDValue(N, 0);
> > +    SDLoc DL(Op);
> > +    EVT VT = Op.getValueType();
> > +    SDValue UDIVREM = DAG.getNode(ISD::UDIVREM, DL, DAG.getVTList(VT, VT),
> > +      N->getOperand(0), N->getOperand(1));
> > +    Results.push_back(UDIVREM);
> > +    break;
> > +  }
> > +  case ISD::UREM: {
> > +    SDValue Op = SDValue(N, 0);
> > +    SDLoc DL(Op);
> > +    EVT VT = Op.getValueType();
> > +    SDValue UDIVREM = DAG.getNode(ISD::UDIVREM, DL, DAG.getVTList(VT, VT),
> > +      N->getOperand(0), N->getOperand(1));
> > +    Results.push_back(UDIVREM.getValue(1));
> > +    break;
> > +  }
> >    default:
> >      return;
> >    }
> > -- 
> > 1.9.0
> > 

-- 
Jan Vesely <jan.vesely at rutgers.edu>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140425/4b97b005/attachment.sig>


More information about the llvm-commits mailing list