This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch, mips] Fix optimization bug involving nor instruction


Good spot!

"Steve Ellcey " <sellcey@mips.com> writes:
> diff --git a/gcc/config/mips/mips.c b/gcc/config/mips/mips.c
> index 5993aab..ffb0b53 100644
> --- a/gcc/config/mips/mips.c
> +++ b/gcc/config/mips/mips.c
> @@ -3796,6 +3796,18 @@ mips_rtx_costs (rtx x, int code, int outer_code, int opno ATTRIBUTE_UNUSED,
>  	      return true;
>  	    }
>  	}
> +      /* (AND (NOT op0) (NOT op1) is a nor operation that can be done in
> +	 a single instruction.  */
> +      if (!TARGET_MIPS16 && (GET_CODE (XEXP (x, 0)) == NOT)
> +	  && (GET_CODE (XEXP (x, 1)) == NOT))
> +	{
> +	  rtx op0 = XEXP (x, 0);
> +	  rtx op1 = XEXP (x, 1);
> +	  cost = GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 2 : 1;
> +          *total = COSTS_N_INSNS (cost) + set_src_cost (XEXP (op0, 0), speed)
> +		   + rtx_cost (XEXP (op1, 0), GET_CODE (op1), 1, speed);
> +	  return true;
> +	}

We should use set_src_cost for both operands (the idea being that only
a register is allowed, and that anything else will end up being a SET_SRC).
I think the formatting should be something like:

      /* (AND (NOT op0) (NOT op1)) is a NOR operation that can be done in
	 a single instruction.  */
      if (!TARGET_MIPS16
	  && GET_CODE (XEXP (x, 0)) == NOT
	  && GET_CODE (XEXP (x, 1)) == NOT)
	{
	  cost = GET_MODE_SIZE (mode) > UNITS_PER_WORD ? 2 : 1;
	  *total = (COSTS_N_INSNS (cost)
		    + set_src_cost (XEXP (XEXP (x, 0), 0), speed)
		    + set_src_cost (XEXP (XEXP (x, 1), 0), speed));
	  return true;
	}

OK with that change, thanks.

Richard


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]