Bug 51683

Summary: [4.7 Regression] __builtin_memcpy etc. with constant first argument optimized away by ccp
Product: gcc Reporter: Jakub Jelinek <jakub>
Component: tree-optimizationAssignee: Jakub Jelinek <jakub>
Status: RESOLVED FIXED    
Severity: normal Keywords: wrong-code
Priority: P3    
Version: 4.7.0   
Target Milestone: 4.7.0   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2011-12-27 00:00:00
Attachments: gcc47-pr51683.patch

Description Jakub Jelinek 2011-12-27 11:18:42 UTC
static inline void *
bar (void *p, void *q, int r)
{
  return __builtin_memcpy (p, q, r);
}

void *
foo (void *p)
{
  return bar ((void *) 0x12345000, p, 256);
}

at -O2 starting with http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=175290
is optimized away.  While the return value from memcpy is known to be constant and we know that constant, we ignore the other side-effects of the call.
Comment 1 Jakub Jelinek 2011-12-27 11:33:01 UTC
Created attachment 26188 [details]
gcc47-pr51683.patch

Untested fix.
Comment 2 Jakub Jelinek 2011-12-31 23:54:00 UTC
Author: jakub
Date: Sat Dec 31 23:53:57 2011
New Revision: 182761

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=182761
Log:
	PR tree-optimization/51683
	* tree-ssa-propagate.c (substitute_and_fold): Don't optimize away
	calls with side-effects.
	* tree-ssa-ccp.c (ccp_fold_stmt): Likewise.

	* gcc.dg/pr51683.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr51683.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-ccp.c
    trunk/gcc/tree-ssa-propagate.c
Comment 3 Jakub Jelinek 2011-12-31 23:55:28 UTC
Fixed.