This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[C++ PATCH] PR middle-end/12454: Improve gimplification of if(1)


The following patch resolves PR middle-end/12454 which is an ICE on
valid regression on mainline, caused by the C++ gimplifier blowing
up the stack on Darwin (which has a low stack size limit).

The solution is to special case the lowering of C++'s IF_STMT where
the condition is a compile-time constant and the unexecuted clause
of the conditional is empty.

The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all default languages, and regression tested with a
top-level "make -k check" with no new failures.  I've also confirmed
on powerpc-apple-darwin7.6.0 that g++.dg/parse/stack1.C can now be
increased to at least twice its current depth without failing.

Ok for mainline?


2004-12-12  Roger Sayle  <roger@eyesopen.com>

	PR middle-end/12454
	* cp-gimplify.c (gimplify_if_stmt): Optimize the case where the
	condition is a constant and the unexecuted clause is empty.


Index: cp-gimplify.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-gimplify.c,v
retrieving revision 1.14
diff -c -3 -p -r1.14 cp-gimplify.c
*** cp-gimplify.c	15 Nov 2004 22:46:25 -0000	1.14
--- cp-gimplify.c	12 Dec 2004 19:10:36 -0000
*************** genericize_eh_spec_block (tree *stmt_p)
*** 85,93 ****
  static void
  gimplify_if_stmt (tree *stmt_p)
  {
!   tree stmt, then_, else_;

    stmt = *stmt_p;
    then_ = THEN_CLAUSE (stmt);
    else_ = ELSE_CLAUSE (stmt);

--- 85,94 ----
  static void
  gimplify_if_stmt (tree *stmt_p)
  {
!   tree stmt, cond, then_, else_;

    stmt = *stmt_p;
+   cond = IF_COND (stmt);
    then_ = THEN_CLAUSE (stmt);
    else_ = ELSE_CLAUSE (stmt);

*************** gimplify_if_stmt (tree *stmt_p)
*** 96,102 ****
    if (!else_)
      else_ = build_empty_stmt ();

!   stmt = build3 (COND_EXPR, void_type_node, IF_COND (stmt), then_, else_);
    *stmt_p = stmt;
  }

--- 97,108 ----
    if (!else_)
      else_ = build_empty_stmt ();

!   if (integer_nonzerop (cond) && !TREE_SIDE_EFFECTS (else_))
!     stmt = then_;
!   else if (integer_zerop (cond) && !TREE_SIDE_EFFECTS (then_))
!     stmt = else_;
!   else
!     stmt = build3 (COND_EXPR, void_type_node, cond, then_, else_);
    *stmt_p = stmt;
  }


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]