public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled
@ 2005-02-21 14:54 pinskia at gcc dot gnu dot org
  2005-02-21 14:57 ` [Bug tree-optimization/20115] " pinskia at gcc dot gnu dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-21 14:54 UTC (permalink / raw)
  To: gcc-bugs

Take the following code, we should not abort:
int func_pure (void);
void func_other (int);
int global_int;
int func_pure (void) { return global_int; }
void func_other (int a)
{
  global_int = a + 1;
}
int f(void)
{
  int a;
  a = func_pure();
  func_other (a);
  a = func_pure (); // We are removing this function call
  return a;
}
void abort (void);

int main(void)
{
  global_int = 10;
  if (f() != 11)
    abort ();
}

-- 
           Summary: [4.0 Regression] Pure functions are missed handled
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are missed handled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
@ 2005-02-21 14:57 ` pinskia at gcc dot gnu dot org
  2005-02-21 15:15 ` pinskia at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-21 14:57 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are missed handled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
  2005-02-21 14:57 ` [Bug tree-optimization/20115] " pinskia at gcc dot gnu dot org
@ 2005-02-21 15:15 ` pinskia at gcc dot gnu dot org
  2005-02-21 15:44 ` [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled pinskia at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-21 15:15 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |20100
              nThis|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
  2005-02-21 14:57 ` [Bug tree-optimization/20115] " pinskia at gcc dot gnu dot org
  2005-02-21 15:15 ` pinskia at gcc dot gnu dot org
@ 2005-02-21 15:44 ` pinskia at gcc dot gnu dot org
  2005-02-22 14:06 ` belyshev at depni dot sinp dot msu dot ru
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-21 15:44 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[4.0 Regression] Pure       |[4.0 Regression] Pure
                   |functions are missed handled|functions are mishandled


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2005-02-21 15:44 ` [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled pinskia at gcc dot gnu dot org
@ 2005-02-22 14:06 ` belyshev at depni dot sinp dot msu dot ru
  2005-02-22 18:27 ` jakub at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: belyshev at depni dot sinp dot msu dot ru @ 2005-02-22 14:06 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
      Known to fail|                            |4.0.0
      Known to work|                            |3.3.6 3.4.4
   Last reconfirmed|0000-00-00 00:00:00         |2005-02-22 07:28:59
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2005-02-22 14:06 ` belyshev at depni dot sinp dot msu dot ru
@ 2005-02-22 18:27 ` jakub at gcc dot gnu dot org
  2005-02-22 18:41 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu dot org @ 2005-02-22 18:27 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jakub at gcc dot gnu dot org  2005-02-22 14:15 -------
This is a DOM bug.
Comment above lookup_avail_expr says:
   NOTE: This function assumes that STMT is a MODIFY_EXPR node that
   contains no CALL_EXPR on its RHS and makes no volatile nor
   aliased references.  */
and I have no reason not to believe this, if not perhaps for const calls, then
certainly for pure calls.  For pure calls the code would need to invalidate
all recorded pure calls whenever a stmt might modify global state.
But optimize_stmt/eliminate_redundant_computations will happily call
lookup_avail_expr with a CALL_EXPR on the RHS, because const/pure calls don't
have TREE_SIDE_EFFECTS set.

I have tried:
--- tree-ssa-dom.c.jj  2005-02-17 20:02:58.000000000 +0100
+++ tree-ssa-dom.c      2005-02-22 14:40:14.912216290 +0100
@@ -2964,7 +2964,8 @@ optimize_stmt (struct dom_walk_data *wal
                        || (TREE_CODE (stmt) == MODIFY_EXPR
                            && ! TREE_SIDE_EFFECTS (TREE_OPERAND (stmt, 1)))
                        || TREE_CODE (stmt) == COND_EXPR
-                       || TREE_CODE (stmt) == SWITCH_EXPR));
+                       || TREE_CODE (stmt) == SWITCH_EXPR)
+                    && get_call_expr_in (stmt) == NULL);

   if (may_optimize_p)
     may_have_exposed_new_symbols

which fixes this, but it seems no other tree-SSA optimization is able to optimize
say extern int foo (void) __attribute__((pure)); ... a = foo (); a += foo ();
into a = 2 * foo ();, fortunately RTL optimizations optimize that.

If const calls are actually handled correctly by lookup_avail_expr, then
the comment above it ought to be changed and we could only avoid optimizing
DECL_IS_PURE calls in addition to TREE_SIDE_EFFECTS rhs' in optimize_stmt.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at redhat dot com,
                   |                            |dnovillo at redhat dot com
           Severity|normal                      |critical


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2005-02-22 18:27 ` jakub at gcc dot gnu dot org
@ 2005-02-22 18:41 ` pinskia at gcc dot gnu dot org
  2005-02-22 19:01 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-22 18:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-22 14:19 -------
Note this was cause by:
2005-01-26  Diego Novillo  <dnovillo@redhat.com>

        PR tree-optimization/19633
        * tree-ssa-alias.c (ptr_is_dereferenced_by): Also handle
        CALL_EXPRs.
        (maybe_create_global_var): Do not create .GLOBAL_VAR if there
        are no call-clobbered variables.
        * tree-outof-ssa.c (check_replaceable): Return false for calls
        with side-effects.




-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2005-02-22 18:41 ` pinskia at gcc dot gnu dot org
@ 2005-02-22 19:01 ` pinskia at gcc dot gnu dot org
  2005-02-22 19:50 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-22 19:01 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-22 14:21 -------
Also note that DOM is doing the "correct" thing as the DOM does not know that func_other could 
change the value of func_pure.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2005-02-22 19:01 ` pinskia at gcc dot gnu dot org
@ 2005-02-22 19:50 ` pinskia at gcc dot gnu dot org
  2005-02-22 19:54 ` dnovillo at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-02-22 19:50 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-02-22 14:56 -------
> For pure calls the code would need to invalidate
> all recorded pure calls whenever a stmt might modify global state.
Yes this was done with GLOBAL_VAR before Diego's patch but now it is not done with anything else.  
This is basically the same issue as PR 20100.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2005-02-22 19:50 ` pinskia at gcc dot gnu dot org
@ 2005-02-22 19:54 ` dnovillo at gcc dot gnu dot org
  2005-02-23  1:12 ` dnovillo at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2005-02-22 19:54 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |dnovillo at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-02-22 07:28:59         |2005-02-22 14:58:42
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2005-02-22 19:54 ` dnovillo at gcc dot gnu dot org
@ 2005-02-23  1:12 ` dnovillo at gcc dot gnu dot org
  2005-02-23 12:30 ` cvs-commit at gcc dot gnu dot org
  2005-02-23 15:23 ` steven at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2005-02-23  1:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dnovillo at gcc dot gnu dot org  2005-02-22 18:26 -------

Testing patch.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2005-02-23  1:12 ` dnovillo at gcc dot gnu dot org
@ 2005-02-23 12:30 ` cvs-commit at gcc dot gnu dot org
  2005-02-23 15:23 ` steven at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2005-02-23 12:30 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2005-02-23 05:08 -------
Subject: Bug 20115

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/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled
  2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
                   ` (10 preceding siblings ...)
  2005-02-23 12:30 ` cvs-commit at gcc dot gnu dot org
@ 2005-02-23 15:23 ` steven at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-02-23 15:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From steven at gcc dot gnu dot org  2005-02-23 11:23 -------
http://gcc.gnu.org/ml/gcc-patches/2005-02/msg01387.html

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2005-02-23 11:23 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-21 14:54 [Bug tree-optimization/20115] New: [4.0 Regression] Pure functions are missed handled pinskia at gcc dot gnu dot org
2005-02-21 14:57 ` [Bug tree-optimization/20115] " pinskia at gcc dot gnu dot org
2005-02-21 15:15 ` pinskia at gcc dot gnu dot org
2005-02-21 15:44 ` [Bug tree-optimization/20115] [4.0 Regression] Pure functions are mishandled pinskia at gcc dot gnu dot org
2005-02-22 14:06 ` belyshev at depni dot sinp dot msu dot ru
2005-02-22 18:27 ` jakub at gcc dot gnu dot org
2005-02-22 18:41 ` pinskia at gcc dot gnu dot org
2005-02-22 19:01 ` pinskia at gcc dot gnu dot org
2005-02-22 19:50 ` pinskia at gcc dot gnu dot org
2005-02-22 19:54 ` dnovillo at gcc dot gnu dot org
2005-02-23  1:12 ` dnovillo at gcc dot gnu dot org
2005-02-23 12:30 ` cvs-commit at gcc dot gnu dot org
2005-02-23 15:23 ` steven at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).