This is the mail archive of the gcc@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]

Re: random thought - optimizer


Jeff writes:
> If/when there's a way to tell that a MEM is local to a procedure, then it
> is trivial for our SSA DCE optimizer to remove loads/stores to that variable
> if they do not contribute to the externally visible result of the program.

Terrific.  This possibly has the potential to get rid of a major g++
performance problem: when a temporary object with two or more fields
is passed by an inline function, we almost always wind up with dead
stores (ADDRESSOF takes care of the one-field case).  Can the SSA
DCE optimizer kill the dead stores?  Here's an example of a typical
case -- a bit vector with an overloaded [] operator where the operator[]
returns a proxy object:

--------------------------------------------------------------------------
class bitref;

class bitvec {
public:
    bitvec(unsigned len);
    bool test(unsigned idx) const;
    bool set(unsigned idx, bool value);
    bool operator[](unsigned idx) const { return test(idx); }
    inline bitref operator[](unsigned idx);
private:
    unsigned long* data;
};


class bitref {
public:
    bitref(bitvec& obj, unsigned idx) : obj_(obj), idx_(idx) {}
    operator bool() const { return obj_.test(idx_);}
    bitref& operator=(bool value) { obj_.set(idx_, value); return *this; }
private:
    bitvec& obj_;
    unsigned idx_;
};

inline bitref bitvec::operator[](unsigned idx) { return bitref(*this, idx); }

// This is the function I care about
void fill(bitvec& vec, unsigned lo, unsigned hi, bool value) {
    for (unsigned i = lo; i <= hi; i++)
	vec[i] = value;
}
--------------------------------------------------------------------------

The sparc code for 3.0 looks like this (passed through c++filt): (-O2)
(inner loop of "fill" only)

.LL11:
	mov	%i1, %o1
	st	%i0, [%fp-24]
	mov	%i0, %o0
	call	bitvec::set(unsigned, bool), 0
	mov	%i3, %o2
	add	%i1, 1, %i1
	cmp	%i1, %i2
	bleu,a	.LL11
	st	%i1, [%fp-20]

Note the two useless st instructions.


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