This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/16987] New: Excessive stack allocation (totally unused)
- From: "giovannibajo at libero dot it" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 Aug 2004 18:10:13 -0000
- Subject: [Bug tree-optimization/16987] New: Excessive stack allocation (totally unused)
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
-------------------------------------------------------------------
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