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

Tom Stellard tom at stellard.net
Fri Apr 25 12:21:00 PDT 2014


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.

-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
> 



More information about the llvm-commits mailing list