This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[g++] inheritance break basic optimisation
- To: gcc-bugs at gcc dot gnu dot org
- Subject: [g++] inheritance break basic optimisation
- From: pollux <duret_g at epita dot fr>
- Date: 07 Sep 1999 17:00:46 +0200
Hi,
I don't know if this is actually a bug, but it seems like to me.
Under some case, g++ don't remove multilication by 1 applied on integer
(with optimization turned on).
I noticed strange code generation with the following source.
BTW, I'm running gcc-2.95.1 (with -O3) on a Linux-i586.
======= test.cc =======
class A{
};
class Int : public A {
public:
Int(int i) : _val(i) {}
Int& operator*=(const Int& rvalue)
{
_val *= rvalue._val;
return *this;
}
const Int operator*(const Int& rvalue) const
{
return Int(*this) *= rvalue;
}
private:
int _val;
};
Int disassemble_this(Int t)
{
return t *= 1; // '*= 1' is not done, OK
} // t is just copied
Int disassemble_this2(const Int t)
{
return t * 1; // '* 1' _is_ done,
} // there _is_ a 'imul' by a 1 loaded register
========================
The curious part is that when I remove the inheretance from A
both operations get optimized. IMHO, there is something about the
copy constructor. Besides if I add a copy constructor to A, say
====
class Int : public A {
// ...
Int(const Int& i) : _val(i._val) {}
// ...
};
====
then, verythings get optimized.
So is this normal, does the default copy constructor forbid optimization
when there is inheritance ?
--
Alexandre 'Pollux' Duret-Lutz