Bug 20100 - [4.0 Regression] LIM is pulling out a pure function even though there is something which can modify global memory
Summary: [4.0 Regression] LIM is pulling out a pure function even though there is some...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.0
Assignee: Diego Novillo
URL:
Keywords: wrong-code
Depends on: 20115
Blocks:
  Show dependency treegraph
 
Reported: 2005-02-20 03:04 UTC by Hans-Peter Nilsson
Modified: 2005-02-23 11:22 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu, cris-axis-elf
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-02-20 08:55:18


Attachments
Test-case (388 bytes, text/plain)
2005-02-20 03:10 UTC, Hans-Peter Nilsson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hans-Peter Nilsson 2005-02-20 03:04:31 UTC
In the test-case to be attached and entered in gcc.c-torture/execute
alt. gcc.dg/torture as prNNNNN-1.c, there's a call to get_n, which
is moved out of the loop.  This happens before rtl passes.
The FC3-bundled gcc known as gcc-3.4.2-6.fc3 (for i686) does not
have this bug.  Trunk as of LAST_UPDATED "Sat Feb 19 00:34:51 UTC 2005"
has this bug, apparent with cris-axis-elf and i686-pc-linux-gnu.
Comment 1 Hans-Peter Nilsson 2005-02-20 03:10:09 UTC
Created attachment 8237 [details]
Test-case

The " && n < 5" condition is there only to make the test terminate, as the bug
would otherwise cause the program to loop until timeout.
Bug-fixer should check that the program still works when removing that
condition.
Comment 2 Hans-Peter Nilsson 2005-02-20 03:16:44 UTC
Correction to the description:
s/there's a call to get_n/in function get_n, there's loop calling function
ring_empty/.
Comment 3 Hans-Peter Nilsson 2005-02-20 03:32:29 UTC
Observed at -O2.
Comment 4 Andrew Pinski 2005-02-20 06:16:32 UTC
Currently in 4.0.x, pure/const is found by the rtl and not by tree wise (now on the tree profiling branch 
it is found on the tree level).

Then again this might be fixed by:
2005-02-19  Zdenek Dvorak  <dvorakz@suse.cz>
            Jakub Jelinek  <jakub@redhat.com>

        PR tree-optimization/19828
        * tree-ssa-loop-im.c: Add a TODO comment.
        (movement_possibility): Return MOVE_PRESERVE_EXECUTION for calls
        without side-effects.
Comment 5 Hans-Peter Nilsson 2005-02-20 08:55:17 UTC
I don't really understand this part of comment #4 which apparently is the reason
for relabelling this PR as rtl-optimization: "Currently in 4.0.x, pure/const is
found by the rtl and not by tree wise".  See the bug description, where I
explicitly state that the invalid transformation is done already when RTL is
generated (that is, as evident in the first dump).

Though looking in GCC, it seems that indeed RTL is responsible for finding
const and pure code.  But that would mean that there's a bug in the RTL-dumping
framework: that it isn't the *initial* RTL that is dumped.
I think I'll have a look so I assign myself this PR.

The bug is still present with LAST_UPDATED "Sun Feb 20 07:53:10 UTC 2005"
so the change referred to apparently doesn't handle this bug even though the
PR and changed code seems related.
Comment 6 Andrew Pinski 2005-02-20 15:41:03 UTC
Actually this is tree aliasing issue. LIM is still doing its job as it does not know that inc_g can change 
memory and that ring_empty accesses it.

This was like my testcase in PR 19828.
Comment 7 Andrew Pinski 2005-02-20 15:44:35 UTC
This looks like PR 19828's comment 1 testcase which by the way still fails.
Comment 8 Andrew Pinski 2005-02-20 15:50:01 UTC
And here is a reduced (and self contained) testcase for that case:
int func_pure (void) __attribute__ ((pure));
void func_other (int);
int global_int;
void abort ();
void func_other(int a)
{
  if (a != global_int)
   abort ();
  global_int++;
}

int func_pure(void)
{
  return global_int;
}

int
func_loop (int arg)
{
 // global_int ++;
  while (arg--)
      func_other (func_pure ());
}

int main(void)
{
  func_loop(10);
  return 0;
}

Uncommenting global_int++; will cause the testcase to work as we have vops now.
I think this is just like the testcase which was attached in comment #1 because if I add a variable and 
have it set a global variable, it works too.
Comment 9 Hans-Peter Nilsson 2005-02-20 18:50:36 UTC
I'm unassigning this PR to avoid giving an impression that I'm about to solve
it.  (I might be, but I have to read up on tree-ssa first.)

I'd be happy if someone else fixed it, as long as my test-case is committed and
solved: committed+solved with, as well as solved without the " && n < 5".

(The test-case in comment #8 likely has some merit too but isn't the reason for
this report.  It also uses user-defined attributes and so is different in that
aspect too.)
Comment 10 Andrew Pinski 2005-02-20 19:02:00 UTC
One more note, we do the correct thing with " --param global-var-threshold=0" so this shows that we 
have aliasing issue.  Diego, why don't we create the .GLOBAL_VAR otherwise?
Comment 11 Andrew Pinski 2005-02-20 23:07:51 UTC
PR 20115 shows it is bigger deal than just LIM and that pure function handling is just broken.
Comment 12 GCC Commits 2005-02-23 05:08:50 UTC
Subject: Bug 20100

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	dnovillo@gcc.gnu.org	2005-02-23 05:08:33

Modified files:
	gcc            : ChangeLog tree-optimize.c tree-pass.h 
	                 tree-ssa-alias.c tree-ssa-operands.c tree-ssa.c 
	gcc/testsuite  : ChangeLog 
	gcc/testsuite/gcc.dg/tree-ssa: 20040517-1.c 
Added files:
	gcc/testsuite/gcc.dg: pr20100.c pr20115-1.c pr20115.c 

Log message:
	PR tree-optimization/20100
	PR tree-optimization/20115
	* tree-optimize.c (init_tree_optimization_passes): Remove
	pass_maybe_create_global_var.
	* tree-pass.h (pass_maybe_create_global_var): Remove.
	* tree-ssa-alias.c (aliases_computed_p): Declare.
	(struct alias_info): Add field NUM_PURE_CONST_CALLS_FOUND.
	(count_calls_and_maybe_create_global_var): Remove.
	(pass_maybe_create_global_var): Remove.
	(init_alias_info): Do not declare aliases_computed_p.
	(maybe_create_global_var): If the function contains no
	call-clobbered variables and a mix of pure/const and regular
	function calls, create .GLOBAL_VAR.
	Mark all call-clobbered variables for renaming.
	(merge_pointed_to_info): Update comment.
	(add_pointed_to_var): Likewise.
	(is_escape_site): Likewise.
	Accept struct alias_info * instead of size_t *.
	Update all users.
	Update AI->NUM_CALLS_FOUND and AI->NUM_PURE_CONST_CALLS_FOUND
	as necessary.
	* tree-ssa-operands.c (get_call_expr_operands): If
	ALIASES_COMPUTED_P is false, do not add call-clobbering
	operands.
	* tree-ssa.c (init_tree_ssa): Set ALIASES_COMPUTED_P to false.
	(delete_tree_ssa): Likewise.
	
	testsuite/ChangeLog
	
	PR tree-optimization/20100
	PR tree-optimization/20115
	* gcc.dg/pr20115.c: New test.
	* gcc.dg/pr20115-1.c: New test.
	* gcc.dg/pr20100.c: New test.
	* gcc.dg/tree-ssa/20040517-1.c: Expect virtual operands for
	call-clobbered variables after alias1.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.7566&r2=2.7567
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-optimize.c.diff?cvsroot=gcc&r1=2.73&r2=2.74
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-pass.h.diff?cvsroot=gcc&r1=2.26&r2=2.27
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-alias.c.diff?cvsroot=gcc&r1=2.70&r2=2.71
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa-operands.c.diff?cvsroot=gcc&r1=2.62&r2=2.63
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/tree-ssa.c.diff?cvsroot=gcc&r1=2.77&r2=2.78
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5071&r2=1.5072
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr20100.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr20115-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr20115.c.diff?cvsroot=gcc&r1=NONE&r2=1.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/tree-ssa/20040517-1.c.diff?cvsroot=gcc&r1=1.3&r2=1.4

Comment 14 GCC Commits 2005-02-23 22:20:56 UTC
Subject: Bug 20100

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	hp@gcc.gnu.org	2005-02-23 22:20:49

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.c-torture/execute: pr20100-1.c 

Log message:
	PR tree-optimization/20100
	* gcc.c-torture/execute/pr20100-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.5080&r2=1.5081
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/pr20100-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1