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] Optimize (x * 8) | 5 and (x << 3) ^ 3 to use lea (PR target/48688)


On Wed, Apr 20, 2011 at 10:27:36AM -0700, Richard Henderson wrote:
> On 04/20/2011 09:09 AM, Jakub Jelinek wrote:
> > Hi!
> > 
> > This splitter allows us to optimize (x {* {2,4,8},<< {1,2,3}}) {|,^} y
> > for constant integer y <= {1ULL,3ULL,7ULL} using lea{l,q} (| or ^ in
> > that case, when the low bits are known to be all 0, is like plus).
> > 
> > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> > 
> > 2011-04-20  Jakub Jelinek  <jakub@redhat.com>
> > 
> > 	PR target/48688
> > 	* config/i386/i386.md (*lea_general_4): New define_insn_and_split.
> 
> Any chance you could do this in combine instead?  Shift-and-add patterns
> are a fairly common architectural feature...

I've tried to do it in simplify-rtx.c, unfortunately combine.c does exactly
opposite canonicalization and thus it results in endless recursion:

      /* If we are adding two things that have no bits in common, convert
         the addition into an IOR.  This will often be further simplified,
         for example in cases like ((a & 1) + (a & 2)), which can
         become a & 3.  */

      if (GET_MODE_BITSIZE (mode) <= HOST_BITS_PER_WIDE_INT
          && (nonzero_bits (XEXP (x, 0), mode)
              & nonzero_bits (XEXP (x, 1), mode)) == 0)
        {
          /* Try to simplify the expression further.  */
          rtx tor = simplify_gen_binary (IOR, mode, XEXP (x, 0), XEXP (x, 1));
          temp = combine_simplify_rtx (tor, mode, in_dest, 0);

          /* If we could, great.  If not, do not go ahead with the IOR
             replacement, since PLUS appears in many special purpose
             address arithmetic instructions.  */
          if (GET_CODE (temp) != CLOBBER && temp != tor)
            return temp;
        }

So at least it can't be done in simplify_binary_operation_1.

	Jakub


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