User account creation filtered due to spam.

Bug 23777 - Does not remove all references to var
Summary: Does not remove all references to var
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.1.0
: P2 enhancement
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
Keywords: alias, missed-optimization, TREE
Depends on: 20912
  Show dependency treegraph
Reported: 2005-09-08 09:59 UTC by Richard Biener
Modified: 2007-03-05 16:56 UTC (History)
2 users (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed: 2006-09-17 08:21:44

reduced testcase from gcc.i (278 bytes, text/plain)
2005-09-08 10:00 UTC, Richard Biener

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2005-09-08 09:59:10 UTC
The tree optimizers cannot remove all references to multilib_exclusions_var,
while RTL does.
Comment 1 Richard Biener 2005-09-08 10:00:59 UTC
Created attachment 9689 [details]
reduced testcase from gcc.i

Testcase.  Compile with -O2, compare asm and tree-vars dump.
Note: testcase contains uses of uninitialized variables.
Comment 2 Paolo Bonzini 2005-09-08 12:02:01 UTC
Even more reduced:

extern void f(char *const *);
void g (char **o)
  static const char *const multilib_exclusions_raw[] = { 0 };
  const char *const *q = multilib_exclusions_raw;

  f (o);
  while (*q++)
    f (o);

The strange thing is, turn the loop into do...while, and it cannot eliminate
multilib_exclusions_raw not even at the RTL level.  Actually it cannot eliminate
the loop at all if it is a do...while.

Comment 3 Andrew Pinski 2005-09-08 12:04:04 UTC
Reduced testcase:
static const char *const multilib_exclusions_raw[] = {0};
struct obstack {
  char *next_free;
static struct obstack multilib_obstack;
int main (int argc, const char **argv)
  const char *p;
  const char *const *q;
  q = multilib_exclusions_raw;
  while ((p = *q++) != (char *) 0)
    int __len = (__builtin_strlen (p));
    __builtin_memcpy ((multilib_obstack.next_free), 0, (__len));    
Comment 4 Andrew Pinski 2005-09-08 12:09:13 UTC
With Paolo's testcase we get the following tree dump in .ch (after copy loop header):
g (o)
  static const char * const multilib_exclusions_raw[1] = {0B};
  const char * const * q;
  static const char * const multilib_exclusions_raw[1] = {0B};
  _Bool D.1280;
  const char * const D.1279;

<bb 0>:
  #   multilib_exclusions_raw_11 = V_MAY_DEF <multilib_exclusions_raw_9>;
  #   TMT.6_12 = V_MAY_DEF <TMT.6_10>;
  f (o_3);
  #   VUSE <multilib_exclusions_raw_11>;
  D.1279_18 = multilib_exclusions_raw[0];
  q_19 = &multilib_exclusions_raw[1];
  if (D.1279_18 != 0B) goto <L0>; else goto <L2>;

  # TMT.6_22 = PHI <TMT.6_14(1), TMT.6_12(0)>;
  # multilib_exclusions_raw_21 = PHI <multilib_exclusions_raw_13(1), multilib_exclusions_raw_11(0)>;
  # q_20 = PHI <q_6(1), q_19(0)>;
  #   multilib_exclusions_raw_13 = V_MAY_DEF <multilib_exclusions_raw_21>;
  #   TMT.6_14 = V_MAY_DEF <TMT.6_22>;
  f (o_3);
  #   VUSE <multilib_exclusions_raw_13>;
  #   VUSE <TMT.6_14>;
  D.1279_4 = *q_20;
  q_6 = q_20 + 4B;
  if (D.1279_4 != 0B) goto <L0>; else goto <L2>;


Note how there is a V_MAY_DEF on the first f for multilib_exclusions_raw.  That is just wrong since 
multilib_exclusions_raw cannot change.
Comment 5 Andrew Pinski 2005-09-08 18:26:07 UTC
There is another way of fixing this to force ccp do look at those array references even though the 
statement has aliased loads.
Comment 6 Andrew Pinski 2006-01-11 05:49:13 UTC
Actually there is a call clobbering issue here or something like that because I see now where the address of multilib_exclusions_raw escaping (I have to look where we mark the variable as call clobbering).
Comment 7 Richard Biener 2007-03-05 16:55:35 UTC
Subject: Bug 23777

Author: rguenth
Date: Mon Mar  5 16:55:23 2007
New Revision: 122558

2007-03-05  Richard Guenther  <>

	PR tree-optimization/23777
	* gcc.dg/tree-ssa/pr23777.c: New testcase.


Comment 8 Richard Biener 2007-03-05 16:56:18 UTC
This is fixed now on the mainline.  Supposedly by

Author: dnovillo
Date: Fri Mar  2 19:20:14 2007
New Revision: 122484


	* tree-ssa-structalias.c (could_have_pointers): Tidy.
	(get_constraint_for): Likewise.
	(do_structure_copy): Likewise.
	(find_func_aliases): Fix references to MODIFY_EXPR.
	(intra_create_variable_infos): Tidy.
	* tree-ssa-operands.c (add_virtual_operand): Add argument
	When adding members of alias sets, if IS_CALL_SITE is true and
	the symbol is not call-clobbered, skip it.
	Adjust all callers.