Bug 51683 - [4.7 Regression] __builtin_memcpy etc. with constant first argument optimized away by ccp
Summary: [4.7 Regression] __builtin_memcpy etc. with constant first argument optimized...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-12-27 11:18 UTC by Jakub Jelinek
Modified: 2011-12-31 23:55 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-12-27 00:00:00


Attachments
gcc47-pr51683.patch (991 bytes, patch)
2011-12-27 11:33 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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.