On Wed, 18 May 2016, Cesar Philippidis wrote:
> >> +(define_expand "sincossf3"
> >> +  [(set (match_operand:SF 0 "nvptx_register_operand" "=R")
> >> +    (unspec:SF [(match_operand:SF 2 "nvptx_register_operand" "R")]
> >> +               UNSPEC_COS))
> >> +   (set (match_operand:SF 1 "nvptx_register_operand" "=R")
> >> +    (unspec:SF [(match_dup 2)] UNSPEC_SIN))]
> >> +  "flag_unsafe_math_optimizations"
> >> +{
> >> +  emit_insn (gen_sinsf2 (operands[1], operands[2]));
> >> +  emit_insn (gen_cossf2 (operands[0], operands[2]));
> >> +
> >> +  DONE;
> >> +})
> > 
> > Why the emit_insn code?  that seems to be replicating the RTL
> > representation -- you're saying the same thing twice.
> > 
> > Doesn't operands[2] need (conditionally) copying to a new register --
> > what if it aliases operands[1]?
> 
> This patch does that now.

Note that the documentation suggests using 'make_safe_from' to concisely
express conflict resolution:

> diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md
> index 33a4862..69bbb22 100644
> --- a/gcc/config/nvptx/nvptx.md
> +++ b/gcc/config/nvptx/nvptx.md
> @@ -794,6 +794,24 @@
>    ""
>    "%.\\tsqrt%#%t0\\t%0, %1;")
>  
> +(define_expand "sincossf3"
> +  [(set (match_operand:SF 0 "nvptx_register_operand" "=R")
> +     (unspec:SF [(match_operand:SF 2 "nvptx_register_operand" "R")]
> +                UNSPEC_COS))
> +   (set (match_operand:SF 1 "nvptx_register_operand" "=R")
> +     (unspec:SF [(match_dup 2)] UNSPEC_SIN))]
> +  "flag_unsafe_math_optimizations"

... here instead of special-casing the conflict case in curly braces you can
just write:

    "operands[2] = make_safe_from (operands[2], operands[0]);"

> +{
> +  if (REGNO (operands[0]) == REGNO (operands[2]))
> +    {
> +      rtx tmp = gen_reg_rtx (GET_MODE (operands[2]));
> +      emit_insn (gen_rtx_SET (tmp, operands[2]));
> +      emit_insn (gen_sinsf2 (operands[1], tmp));
> +      emit_insn (gen_cossf2 (operands[0], tmp));
> +      DONE;
> +    }
> +})

Alexander

Reply via email to