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: new sign/zero extension elimination pass


On 10/21/2010 12:24 PM, Paolo Bonzini wrote:
> On 10/18/2010 05:42 PM, Andrew Pinski wrote:
>>> > For MIPS, compilation results in the following insns.
>>> >
>>> > (set (reg/v:SI 199)
>>> > (sign_extend:SI (subreg:HI (reg:SI 200) 2)))
>>> >
>>> > ...
>>> >
>>> > (set (reg:QI 203)
>>> > (subreg:QI (reg/v:SI 199) 3))
>>> >
>>> > These insns are the only def and the only use of reg 199, each 
>>> located in a
>>> > different bb.
>>
>> This sounds like a job for GCSE to do.
> 
> Actually, fwprop should _already_ do that if assuming simplify-rtx.c 
> does the simplification of (subreg:QI (sign_extend:SI (subreg:HI (reg:SI 
> 200) 2))) 3).

... which this code should do in simplify_subreg:

  /* Optimize SUBREG truncations of zero and sign extended values.  */
  if ((GET_CODE (op) == ZERO_EXTEND
       || GET_CODE (op) == SIGN_EXTEND)
      && GET_MODE_BITSIZE (outermode) < GET_MODE_BITSIZE (innermode))
    {
      unsigned int bitpos = subreg_lsb_1 (outermode, innermode, byte);

      /* If we're requesting the lowpart of a zero or sign extension,
         there are three possibilities.  If the outermode is the same
         as the origmode, we can omit both the extension and the subreg.
         If the outermode is not larger than the origmode, we can apply
         the truncation without the extension.  Finally, if the outermode
         is larger than the origmode, but both are integer modes, we
         can just extend to the appropriate mode.  */
      if (bitpos == 0)
        {
          enum machine_mode origmode = GET_MODE (XEXP (op, 0));
          if (outermode == origmode)
            return XEXP (op, 0);
          if (GET_MODE_BITSIZE (outermode) <= GET_MODE_BITSIZE (origmode))
            return simplify_gen_subreg (outermode, XEXP (op, 0), origmode,
                                        subreg_lowpart_offset (outermode,
                                                               origmode));
          if (SCALAR_INT_MODE_P (outermode))
            return simplify_gen_unary (GET_CODE (op), outermode,
                                       XEXP (op, 0), origmode);
        }

However, the def of pseudo 200 is "complex enough" that fwprop will not want
to propagate it unless it simplifies to a constant.

It should be enough to tell fwprop that such propagations are always fine
if the destination pseudo has one use only.  In this case register pressure
cannot increase.

Paolo


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