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.
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.
Correction to the description: s/there's a call to get_n/in function get_n, there's loop calling function ring_empty/.
Observed at -O2.
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.
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.
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.
This looks like PR 19828's comment 1 testcase which by the way still fails.
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.
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.)
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?
PR 20115 shows it is bigger deal than just LIM and that pure function handling is just broken.
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
http://gcc.gnu.org/ml/gcc-patches/2005-02/msg01387.html
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