[PATCH] R600/SI: implement range reduction for sin/cos

Matt Arsenault Matthew.Arsenault at amd.com
Fri Jun 20 11:02:17 PDT 2014


On 06/20/2014 10:27 AM, Grigori Goronzy wrote:
> These instructions can only take a limited input range, and return
> the constant value 1 out of range. We should do range reduction to
> be able to process arbitrary values. Use a FRACT instruction after
> normalization to achieve this.
> ---
>   lib/Target/R600/SIInstructions.td | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/lib/Target/R600/SIInstructions.td b/lib/Target/R600/SIInstructions.td
> index f888b8e..2bdcfd2 100644
> --- a/lib/Target/R600/SIInstructions.td
> +++ b/lib/Target/R600/SIInstructions.td
> @@ -2253,12 +2253,12 @@ def : Pat<
>   
>   def : Pat <
>     (fcos f32:$src0),
> -  (V_COS_F32_e32 (V_MUL_F32_e32 $src0, (V_MOV_B32_e32 CONST.TWO_PI_INV)))
> +  (V_COS_F32_e32 (V_FRACT_F32_e32(V_MUL_F32_e32 $src0, (V_MOV_B32_e32 CONST.TWO_PI_INV))))
>   >;
>   
>   def : Pat <
>     (fsin f32:$src0),
> -  (V_SIN_F32_e32 (V_MUL_F32_e32 $src0, (V_MOV_B32_e32 CONST.TWO_PI_INV)))
> +  (V_SIN_F32_e32 (V_FRACT_F32_e32(V_MUL_F32_e32 $src0, (V_MOV_B32_e32 CONST.TWO_PI_INV))))
>   >;
>   
>   def : Pat <
>
I think it would be better to to this with custom lowering rather than 
the instruction patterns. That way DAG combines can see these 
conversions and fold them with other operations if possible, and it's 
already handled that way for R600's version.

Also needs a test



More information about the llvm-commits mailing list