public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/16987] New: Excessive stack allocation (totally unused)
@ 2004-08-11 18:10 giovannibajo at libero dot it
  2004-08-11 18:19 ` [Bug tree-optimization/16987] [3.5 Regression] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: giovannibajo at libero dot it @ 2004-08-11 18:10 UTC (permalink / raw)
  To: gcc-bugs

-------------------------------------------------------------------
typedef int Type;

void check(int);

template <typename To, typename From>
inline int assign(To& a, From b) {
	a = b;
	return 0;
}

template <typename To, typename From>
inline int add(To& a, From b, From c) {
	a = b + c;
	return 0;
}

template <typename T>
class Template;

template <typename T>
class Template {
private:
	T v;
public:
	Template()
		: v(0) {
	}
#if 0
	Template(const Template& y)
		: v(y.v) {
	}
#endif
	Template(const T y)
		: v(y) {
	}
	template <typename T1>
	Template(const T1 y) {
		check(assign(v, y));
	}
	const T& value() const {
		return v;
	}
};

template <typename T>
inline Template<T>
operator+(const Template<T> x, const Template<T> y) {
	T r;
	check(add(r, x.value(), y.value()));
	return r;
}

template <typename T, typename T1>
inline Template<T>
operator+(const T1 x, const Template<T> y)
{
	return Template<T>(x) + y;
}

Type s(int v)
{
	Template<Type> a = v;
	Template<Type> c = 3 + a;
	return c.value();
}
-------------------------------------------------------------------

Try compiling this with -O3, comparing the outputs after changing #if 0 to #if 
1. The .s diff is the following (excluding changes related to a label which 
changes name):


--- bind.s      2004-08-11 06:56:43.000000000 +0200
+++ bind_ctor.s 2004-08-11 06:56:23.000000000 +0200
@@ -6,25 +6,27 @@
 .LCFI2:
-       subl    $16, %esp
+       subl    $64, %esp
 .LCFI3:
-       movl    8(%ebp), %ebx
-       addl    $3, %ebx
+       movl    8(%ebp), %eax
+       leal    3(%eax), %ebx
        pushl   $0
+       movl    %eax, -40(%ebp)
+       movl    $3, -56(%ebp)
 .LCFI4:
        call    _Z5checki
        movl    %ebx, %eax
        movl    -4(%ebp), %ebx
        leave
        ret



(- is #if 0,  + is #if 1).

There are two problems here: first, there is a slight code pessimization which 
should not happen because the code is semantically identical between the two 
cases. Second, there is a *big* increase in stack allocation, for no good 
reason (16 -> 64). Seems like tree-ssa is not able to clean up something.

-- 
           Summary: Excessive stack allocation (totally unused)
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: giovannibajo at libero dot it
                CC: gcc-bugs at gcc dot gnu dot org


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


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

end of thread, other threads:[~2004-09-07  7:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-11 18:10 [Bug tree-optimization/16987] New: Excessive stack allocation (totally unused) giovannibajo at libero dot it
2004-08-11 18:19 ` [Bug tree-optimization/16987] [3.5 Regression] " pinskia at gcc dot gnu dot org
2004-08-11 18:21 ` pinskia at gcc dot gnu dot org
2004-08-11 19:44 ` giovannibajo at libero dot it
2004-08-11 19:45 ` [Bug tree-optimization/16987] [3.3/3.4/3.5 " giovannibajo at libero dot it
2004-08-29 18:25 ` mmitchel at gcc dot gnu dot org
2004-09-03 22:05 ` steven at gcc dot gnu dot org
2004-09-03 22:58 ` rth at gcc dot gnu dot org
2004-09-07  7:31 ` pinskia 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).