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]
Other format: [Raw text]

help interpreting gcc 4.1.1 optimisation bug


I want a reduced test case for this problem for bugzilla, but don't
really know the exact cause. I _think_ code is being improperly
optimized away, but I don't know. This function is part of a
BigInteger library, and works perfectly upto and including -O2, but
produces bogus results at -O3, unless I uncomment the debug_msg()
line, which just dumps the contents of 'i' to the screen. I'm
guessing that without it, the compiler fails to notice that i's
contents are being accessed via the _front8/_back8 pointers, and
throws the preceeding 'i' related code away. Heres the code:

    void Integer::export_bytes(Data& _buffer, PortMode _mode) const
    {
        debug_scope("export_bytes(Data&)");

        Integer i(*this,1);

        if (_mode==SIGNED) {
            if (*mBack & TOP_BIT)
                i.grow(1,0);
            if (sign()<0)
                i.twoscomplement();
        }

        for (UnsignedW* p=i.mFront; p<=i.mBack; p++)
            *p = host2little(*p);

        Unsigned8* _front8 = reinterpret_cast<Unsigned8*>(i.mFront);
        Unsigned8* _back8 = _front8+(i.mSize*WORD_BYTES)-1;
        if (_mode==UNSIGNED)
            while (_back8!=_front8 and *_back8==0)
                _back8--;
        else if (mSign==1)
            while (_back8!=_front8 and *_back8==0 and
                   !(*(_back8-1)&0x80))
                _back8--;
        else
            while (_back8!=_front8 and *_back8==0xff and
                   *(_back8-1)&0x80)
                _back8--;

        //debug_msg(String("Force i\n")+i.dump());

        _buffer.assign(_front8, _back8+1);
    }

Any thoughts on how to proceed?

Andrew Walrond


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