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]

[PATCH] PR middle-end/10472: __builtin_stpcpy RTL (take 2)


On Sun, 4 May 2003, Kaveh R. Ghazi wrote:
> Ah, excellent!  Thanks Roger. :-)
I'm glad I could help with this one :>

> typo "binary"?
Doh!  Thanks for catching this.

> Perhaps just to be thorough, add a test call to mempcpy also?
Done.


The following patch is identical to the original except for the
correction to the ChangeLog entry, and Kaveh's addition of a
second test in the new test case.  I've confirmed the modified
20030504-1.c still compiles fine with my previously built tree.

Ok for mainline?


2003-05-04  Roger Sayle  <roger@eyesopen.com>
	    Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	PR middle-end/10472
	* builtins.c (expand_builtin_memcpy):  Call force_operand on
	expressions and use simplify_gen_binary to create the addition.

	* gcc.c-torture/compile/20030504-1.c: New test case.


Index: builtins.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/builtins.c,v
retrieving revision 1.194
diff -c -3 -p -r1.194 builtins.c
*** builtins.c	3 May 2003 14:25:20 -0000	1.194
--- builtins.c	4 May 2003 02:28:46 -0000
*************** expand_builtin_memcpy (arglist, target,
*** 2311,2320 ****
  #endif
  	  if (endp)
  	    {
! 	      rtx result = gen_rtx_PLUS (GET_MODE (dest_mem), dest_mem, len_rtx);
  	      if (endp == 2)
! 		result = simplify_gen_binary (MINUS, GET_MODE (result), result, const1_rtx);
! 	      return result;
  	    }
  	  else
  	    return dest_mem;
--- 2311,2325 ----
  #endif
  	  if (endp)
  	    {
! 	      rtx result;
! 	      unsigned HOST_WIDE_INT delta = INTVAL (len_rtx);
!
  	      if (endp == 2)
! 		delta--;
!
! 	      result = simplify_gen_binary (PLUS, GET_MODE (dest_mem),
! 					    dest_mem, GEN_INT (delta));
! 	      return force_operand (result, NULL_RTX);
  	    }
  	  else
  	    return dest_mem;
*************** expand_builtin_memcpy (arglist, target,
*** 2338,2347 ****

        if (endp)
          {
! 	  rtx result = gen_rtx_PLUS (GET_MODE (dest_addr), dest_addr, len_rtx);
  	  if (endp == 2)
! 	    result = simplify_gen_binary (MINUS, GET_MODE (result), result, const1_rtx);
! 	  return result;
  	}
        else
  	return dest_addr;
--- 2343,2360 ----

        if (endp)
          {
! 	  rtx result = force_operand (len_rtx, NULL_RTX);
!
  	  if (endp == 2)
! 	    {
! 	      result = simplify_gen_binary (MINUS, GET_MODE (result),
! 					    result, const1_rtx);
! 	      result = force_operand (result, NULL_RTX);
! 	    }
!
! 	  result = simplify_gen_binary (PLUS, GET_MODE (dest_addr),
! 					dest_addr, result);
! 	  return force_operand (result, NULL_RTX);
  	}
        else
  	return dest_addr;


/* Test case from PR middle-end/10472  */

extern void f (char *);

void foo (char *s)
{
  f (__builtin_stpcpy (s, "hi"));
}

void bar (char *s)
{
  f (__builtin_mempcpy (s, "hi", 3));
}


Roger
--


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