Bug 23094 - store ccp, or store copy prop misses an optimization
Summary: store ccp, or store copy prop misses an optimization
Status: ASSIGNED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 enhancement
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords: alias, missed-optimization
: 53870 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-07-27 15:51 UTC by Serge Belyshev
Modified: 2012-07-06 10:06 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-02-09 19:34:25


Attachments
Patch to get the TMT's to properly have a constant value (531 bytes, patch)
2005-07-27 16:08 UTC, Daniel Berlin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Serge Belyshev 2005-07-27 15:51:51 UTC
// This function can be optimized to just *p = *q = 1; at tree level:

void foo (int *p, int *q)
{
  *p = 1;
  *q = 1;
  if (*p != 1)
    link_error ();
}
Comment 1 Andrew Pinski 2005-07-27 15:56:51 UTC
Confirmed.  A weird case but still should be able to optimizated very easily.
Comment 2 Daniel Berlin 2005-07-27 16:04:27 UTC
store CCP returns UNKNOWN_VAL as soon as it sees the TMT, even though the RHS is
completely constant, and even after we set the value of the TMT's to constant.

Even if you change the call to link_error to abort (a noreturn function which
has no v_may_defs),
we don't end up noticing the value is constant, because then we determine that
p_1 has an UNKNOWN_VAL, wihch doesn't actually matter, since the TMT is constant
valued, it doesn't matter that we don't know where exactly the pointer points to.

If the pointer had changed, it would be a new version, or the TMT wouldn't be
constant valued.


I've attached a patch that at least gets the TMT's to constant.
Comment 3 Daniel Berlin 2005-07-27 16:08:09 UTC
Created attachment 9375 [details]
Patch to get the TMT's to properly have a constant value
Comment 4 Steven Bosscher 2005-08-13 10:30:00 UTC
Hmm, can someone explain where in store_ccp we stuff constants 
into the mem_ref field of lattice values?  There are a few places 
where simple_cst_equal is used to compare a constant to mem_ref 
but AFAICT mem_ref is always the lhs of an expression?? 
 
 
Comment 5 Diego Novillo 2005-08-15 14:15:28 UTC
(In reply to comment #4)
> Hmm, can someone explain where in store_ccp we stuff constants 
> into the mem_ref field of lattice values?  There are a few places 
> where simple_cst_equal is used to compare a constant to mem_ref 
> but AFAICT mem_ref is always the lhs of an expression?? 
>  
Yes.  mem_ref holds the actual memory store/load expression (i.e., the
REFERENCE_CLASS_P tree).  The actual constant value is always stored in the
CONST_VAL array.

Comment 6 Andrew Pinski 2005-08-18 13:51:50 UTC
This was not fixed by the patch for PR 21574.
Comment 7 Andrew Pinski 2005-08-18 13:55:13 UTC
I don't know how this was changed to waiting.
Comment 8 Andrew Pinski 2006-04-08 02:32:49 UTC
Store copy prop has the same issue, testcase:
void foo (int *p, int *q, int t)
{
  *p = t;
  *q = t;
  if (*p != 1)
    link_error ();
}
Comment 9 Richard Biener 2008-03-14 19:34:25 UTC
I have a patch.  But maybe trying to optimize this is a little bit expensive?
Comment 10 Richard Biener 2008-03-18 15:31:23 UTC
Similar case that SCCVN could also handle (store_ccp and DOM handle this):

int G;

void __attribute__((noinline))
foo (int i)
{
   if (i > 0)
     G = 3;
   else
     G = 3;

   if (G != 3)
     link_error ();
}

int
main ()
{
   foo (0);
   return 0;
}

(I have a patch for this as well, the above testcase is the same as
gcc.dg/tree-ssa/20040721-1.c)
Comment 11 Richard Biener 2008-08-17 11:26:03 UTC
The store-ccp testcase in comment #10 is fixed by the patch for PR35972.
Still the requested optimization is also performed by DOM.
Comment 12 Richard Biener 2008-08-19 09:08:24 UTC
Subject: Bug 23094

Author: rguenth
Date: Tue Aug 19 09:06:54 2008
New Revision: 139226

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=139226
Log:
2008-08-19  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/35972
	PR tree-optimization/23094
	* tree-ssa-sccvn.h (vn_reference_lookup_pieces): Add maywalk
	parameter.
	* tree-ssa-sccvn.c (copy_reference_ops_from_ref): Properly
	handle MISALIGNED_INDIRECT_REF.
	(get_ref_from_reference_ops): New helper.
	(vn_reference_lookup_pieces): Walk the use-def chain using the
	alias-oracle if requested.
	* tree-ssa-pre.c (phi_translate_1): Do reference lookup with
	walking the use-def chain.
	(compute_avail): But not here.
	(create_component_ref_by_pieces_1): Properly handle
	MISALIGNED_INDIRECT_REF.
	(do_regular_insertion): Handle fully redundant
	expressions after PHI-translation also for SSA_NAME values, not
	only constants.  Correctly use edoubleprime for that.

	* gcc.dg/tree-ssa/ssa-pre-19.c: New testcase.
	* gcc.dg/autopar/reduc-1.c: Move constant initialized arrays to
	global memory.
	* gcc.dg/autopar/reduc-1char.c: Likewise.
	* gcc.dg/autopar/reduc-1short.c: Likewise.
	* gcc.dg/autopar/reduc-2.c: Likewise.
	* gcc.dg/autopar/reduc-2char.c: Likewise.
	* gcc.dg/autopar/reduc-2short.c: Likewise.
	* gcc.dg/autopar/reduc-3.c: Likewise.
	* gcc.dg/tree-ssa/ifc-20040816-1.c: Likewise.
	* gcc.dg/vect/costmodel/i386/costmodel-vect-reduc-1char.c: Likewise.
	* gcc.dg/vect/costmodel/x86_64/costmodel-vect-reduc-1char.c: Likewise.
	* gcc.dg/vect/fast-math-vect-reduc-5.c: Likewise.
	* gcc.dg/vect/fast-math-vect-reduc-7.c: Likewise.
	* gcc.dg/vect/no-trapping-math-2.c: Likewise.
	* gcc.dg/vect/no-trapping-math-vect-111.c: Likewise.
	* gcc.dg/vect/no-trapping-math-vect-ifcvt-11.c: Likewise.
	* gcc.dg/vect/no-trapping-math-vect-ifcvt-12.c: Likewise.
	* gcc.dg/vect/no-trapping-math-vect-ifcvt-13.c: Likewise.
	* gcc.dg/vect/no-trapping-math-vect-ifcvt-14.c: Likewise.
	* gcc.dg/vect/no-trapping-math-vect-ifcvt-15.c: Likewise.
	* gcc.dg/vect/no-vfa-vect-37.c: Likewise.
	* gcc.dg/vect/no-vfa-vect-depend-1.c: Likewise.
	* gcc.dg/vect/pr18400.c: Likewise.
	* gcc.dg/vect/slp-12b.c: Likewise.
	* gcc.dg/vect/slp-14.c: Likewise.
	* gcc.dg/vect/slp-7.c: Likewise.
	* gcc.dg/vect/slp-15.c: Likewise.
	* gcc.dg/vect/slp-16.c: Likewise.
	* gcc.dg/vect/slp-17.c: Likewise.
	* gcc.dg/vect/slp-24.c: Likewise.
	* gcc.dg/vect/slp-28.c: Likewise.
	* gcc.dg/vect/slp-3.c: Likewise.
	* gcc.dg/vect/slp-34.c: Likewise.
	* gcc.dg/vect/slp-6.c: Likewise.
	* gcc.dg/vect/slp-8.c: Likewise.
	* gcc.dg/vect/vect-107.c: Likewise.
	* gcc.dg/vect/vect-108.c: Likewise.
	* gcc.dg/vect/vect-11.c: Likewise.
	* gcc.dg/vect/vect-112.c: Likewise.
	* gcc.dg/vect/vect-115.c: Likewise.
	* gcc.dg/vect/vect-11a.c: Likewise.
	* gcc.dg/vect/vect-34.c: Likewise.
	* gcc.dg/vect/vect-9.c: Likewise.
	* gcc.dg/vect/vect-97.c: Likewise.
	* gcc.dg/vect/vect-align-1.c: Likewise.
	* gcc.dg/vect/vect-float-extend-1.c: Likewise.
	* gcc.dg/vect/vect-floatint-conversion-1.c: Likewise.
	* gcc.dg/vect/vect-ifcvt-16.c: Likewise.
	* gcc.dg/vect/vect-ifcvt-17.c: Likewise.
	* gcc.dg/vect/vect-ifcvt-2.c: Likewise.
	* gcc.dg/vect/vect-ifcvt-3.c: Likewise.
	* gcc.dg/vect/vect-ifcvt-4.c: Likewise.
	* gcc.dg/vect/vect-ifcvt-5.c: Likewise.
	* gcc.dg/vect/vect-ifcvt-6.c: Likewise.
	* gcc.dg/vect/vect-ifcvt-7.c: Likewise.
	* gcc.dg/vect/vect-intfloat-conversion-1.c: Likewise.
	* gcc.dg/vect/vect-intfloat-conversion-2.c: Likewise.
	* gcc.dg/vect/vect-intfloat-conversion-3.c: Likewise.
	* gcc.dg/vect/vect-intfloat-conversion-4a.c: Likewise.
	* gcc.dg/vect/vect-intfloat-conversion-4b.c: Likewise.
	* gcc.dg/vect/vect-multitypes-2.c: Likewise.
	* gcc.dg/vect/vect-multitypes-5.c: Likewise.
	* gcc.dg/vect/vect-reduc-1.c: Likewise.
	* gcc.dg/vect/vect-reduc-1char.c: Likewise.
	* gcc.dg/vect/vect-reduc-1short.c: Likewise.
	* gcc.dg/vect/vect-reduc-2.c: Likewise.
	* gcc.dg/vect/vect-reduc-3.c: Likewise.
	* gcc.dg/vect/vect-shift-1.c: Likewise.
	* gcc.dg/vect/vect-strided-float.c: Likewise.
	* gcc.dg/vect/vect-strided-store-u32-i2.c: Likewise.
	* gcc.dg/vect/wrapv-vect-reduc-2char.c: Likewise.
	* gcc.dg/vect/wrapv-vect-reduc-2short.c: Likewise.
	* gcc.dg/tree-ssa/gen-vect-11.c: Likewise.
	* gcc.dg/tree-ssa/gen-vect-11a.c: Likewise.
	* gcc.dg/tree-ssa/gen-vect-2.c: Likewise.
	* gcc.dg/vect/costmodel/ppc/costmodel-vect-76c.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-19.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/autopar/reduc-1.c
    trunk/gcc/testsuite/gcc.dg/autopar/reduc-1char.c
    trunk/gcc/testsuite/gcc.dg/autopar/reduc-1short.c
    trunk/gcc/testsuite/gcc.dg/autopar/reduc-2.c
    trunk/gcc/testsuite/gcc.dg/autopar/reduc-2char.c
    trunk/gcc/testsuite/gcc.dg/autopar/reduc-2short.c
    trunk/gcc/testsuite/gcc.dg/autopar/reduc-3.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-11.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-11a.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-2.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ifc-20040816-1.c
    trunk/gcc/testsuite/gcc.dg/vect/costmodel/i386/costmodel-vect-reduc-1char.c
    trunk/gcc/testsuite/gcc.dg/vect/costmodel/ppc/costmodel-vect-76c.c
    trunk/gcc/testsuite/gcc.dg/vect/costmodel/x86_64/costmodel-vect-reduc-1char.c
    trunk/gcc/testsuite/gcc.dg/vect/fast-math-vect-reduc-5.c
    trunk/gcc/testsuite/gcc.dg/vect/fast-math-vect-reduc-7.c
    trunk/gcc/testsuite/gcc.dg/vect/no-trapping-math-2.c
    trunk/gcc/testsuite/gcc.dg/vect/no-trapping-math-vect-111.c
    trunk/gcc/testsuite/gcc.dg/vect/no-trapping-math-vect-ifcvt-11.c
    trunk/gcc/testsuite/gcc.dg/vect/no-trapping-math-vect-ifcvt-12.c
    trunk/gcc/testsuite/gcc.dg/vect/no-trapping-math-vect-ifcvt-13.c
    trunk/gcc/testsuite/gcc.dg/vect/no-trapping-math-vect-ifcvt-14.c
    trunk/gcc/testsuite/gcc.dg/vect/no-trapping-math-vect-ifcvt-15.c
    trunk/gcc/testsuite/gcc.dg/vect/no-vfa-vect-37.c
    trunk/gcc/testsuite/gcc.dg/vect/no-vfa-vect-depend-1.c
    trunk/gcc/testsuite/gcc.dg/vect/pr18400.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-12b.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-14.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-15.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-16.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-17.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-24.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-28.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-3.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-34.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-6.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-7.c
    trunk/gcc/testsuite/gcc.dg/vect/slp-8.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-107.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-108.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-11.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-112.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-115.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-11a.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-34.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-9.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-97.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-align-1.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-float-extend-1.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-floatint-conversion-1.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-ifcvt-16.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-ifcvt-17.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-ifcvt-2.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-ifcvt-3.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-ifcvt-4.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-ifcvt-5.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-ifcvt-6.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-ifcvt-7.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-intfloat-conversion-1.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-intfloat-conversion-2.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-intfloat-conversion-3.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-intfloat-conversion-4a.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-intfloat-conversion-4b.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-multitypes-2.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-multitypes-5.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-1.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-1char.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-1short.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-2.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-reduc-3.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-shift-1.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-strided-float.c
    trunk/gcc/testsuite/gcc.dg/vect/vect-strided-store-u32-i2.c
    trunk/gcc/testsuite/gcc.dg/vect/wrapv-vect-reduc-2char.c
    trunk/gcc/testsuite/gcc.dg/vect/wrapv-vect-reduc-2short.c
    trunk/gcc/tree-ssa-pre.c
    trunk/gcc/tree-ssa-sccvn.c
    trunk/gcc/tree-ssa-sccvn.h

Comment 13 Richard Biener 2008-08-19 09:10:58 UTC
Testcase in comment #10 is fixed.  For the original testcase (and the
copyprop variant) I still have a SCCVN patch pending.
Comment 14 Richard Biener 2012-07-06 09:59:28 UTC
*** Bug 53870 has been marked as a duplicate of this bug. ***
Comment 15 Richard Biener 2012-07-06 10:06:08 UTC
Testcase from PR53870:

int f(int *a, int *b)
{
  *a = *b;
  return *b;
}