* Question on Taming the Optimizer
@ 2011-09-28 5:01 Jeffrey Walton
2011-09-28 6:15 ` Jonathan Wakely
2011-09-28 15:00 ` Andrew Haley
0 siblings, 2 replies; 5+ messages in thread
From: Jeffrey Walton @ 2011-09-28 5:01 UTC (permalink / raw)
To: GCC Users List
Hi All,
What is the preferred way to tame the optimizer when two class
functions are producing incorrect results?
There's not much to the class - its a vector with copy semantics. So
it mirrors all vector's public functions, and forwards calls through
the internal vector pointer. The pointer is a boost shared_ptr.
-O2 is giving problems. -O0 is OK, Intel ICC is OK, and Visual Studio is OK.
Jeff
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on Taming the Optimizer
2011-09-28 5:01 Question on Taming the Optimizer Jeffrey Walton
@ 2011-09-28 6:15 ` Jonathan Wakely
2011-09-28 7:37 ` Jeffrey Walton
2011-09-28 15:00 ` Andrew Haley
1 sibling, 1 reply; 5+ messages in thread
From: Jonathan Wakely @ 2011-09-28 6:15 UTC (permalink / raw)
To: noloader; +Cc: GCC Users List
On 28 September 2011 00:41, Jeffrey Walton <noloader@gmail.com> wrote:
> Hi All,
>
> What is the preferred way to tame the optimizer when two class
> functions are producing incorrect results?
Fix your code ;-)
> There's not much to the class - its a vector with copy semantics. So
> it mirrors all vector's public functions, and forwards calls through
> the internal vector pointer. The pointer is a boost shared_ptr.
>
> -O2 is giving problems. -O0 is OK, Intel ICC is OK, and Visual Studio is OK.
As suggested at http://gcc.gnu.org/bugs/ you can try
-fno-strict-aliasing and -fwrapv, if they help your code is broken.
You can also turn off other individual optimisations with -fno-foobar,
see the manual for the various optimizations that are active at -O1
and -O2
> Jeff
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on Taming the Optimizer
2011-09-28 6:15 ` Jonathan Wakely
@ 2011-09-28 7:37 ` Jeffrey Walton
2011-09-28 14:36 ` Jonathan Wakely
0 siblings, 1 reply; 5+ messages in thread
From: Jeffrey Walton @ 2011-09-28 7:37 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: GCC Users List
On Tue, Sep 27, 2011 at 8:03 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 28 September 2011 00:41, Jeffrey Walton <noloader@gmail.com> wrote:
>> Hi All,
>>
>> What is the preferred way to tame the optimizer when two class
>> functions are producing incorrect results?
>
> Fix your code ;-)
That's what I thought, too. I'm kind of surprised that I haven't
gotten a warning out of any of the tools (I run with maximum on all
platforms).
Below is a brief version of what the declarations and definitions look
like. Obviously, the ASSERTs are removed in the 'release'
configuration. The best I can tell, the call to "m_vector->insert(pos,
first, last);" is not being made, but I could be wrong.
We are using LeBlanc's SafeInt, which itself uses unsigned math (so
there should be no undefined behavior). But I don't believe the
SafeInts are being used on the code path leading to the unexpected
behavior.
Oh, and trying to use GDB to debug this is really fun. Sometimes I
think GDB is guessing where it might be after a 'si'.
>> There's not much to the class - its a vector with copy semantics. So
>> it mirrors all vector's public functions, and forwards calls through
>> the internal vector pointer. The pointer is a boost shared_ptr.
>>
>> -O2 is giving problems. -O0 is OK, Intel ICC is OK, and Visual Studio is OK.
>
> As suggested at http://gcc.gnu.org/bugs/ you can try
> -fno-strict-aliasing and -fwrapv, if they help your code is broken.
I actually decided against -fwrapv because I did not want to affect
all compilation units.
> You can also turn off other individual optimisations with -fno-foobar,
> see the manual for the various optimizations that are active at -O1
> and -O2
I was thinking __attribute__((optimize(0))) for the two functions in
question. Is it available in modern GCC versions (ie, 4.0 and above)?
Jeff
template <typename T>
class SecureArray
{
public:
typedef typename std::vector< T, zallocator<T> > SecureVector;
typedef typename zallocator<T>::size_type size_type;
typedef typename SecureVector::value_type value_type;
...
// One of the problem functions
void insert(iterator pos, InputIterator first, InputIterator last);
private:
boost::shared_ptr<SecureVector> m_vector;
}
template <typename T>
template <class InputIterator>
void SecureArray<T>::insert(iterator pos, InputIterator first,
InputIterator last)
{
ASSERT2(first, "Bad first input iterator");
ASSERT2(first >= last, "Input iterators are not valid");
if(!(first >= last))
throw std::length_error("Input iterators are not valid");
// Not sure what the conatiner does here....
ASSERT2(first % sizeof(T) == 0, "InputIterator first slices elements");
ASSERT2(last % sizeof(T) == 0, "InputIterator last slices elements");
ASSERT1(m_vector.get());
m_vector->insert(pos, first, last);
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on Taming the Optimizer
2011-09-28 7:37 ` Jeffrey Walton
@ 2011-09-28 14:36 ` Jonathan Wakely
0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Wakely @ 2011-09-28 14:36 UTC (permalink / raw)
To: noloader; +Cc: GCC Users List
On 28 September 2011 01:40, Jeffrey Walton wrote:
> I was thinking __attribute__((optimize(0))) for the two functions in
> question. Is it available in modern GCC versions (ie, 4.0 and above)?
No, it's much more recent than that:
http://gcc.gnu.org/gcc-4.4/changes.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Question on Taming the Optimizer
2011-09-28 5:01 Question on Taming the Optimizer Jeffrey Walton
2011-09-28 6:15 ` Jonathan Wakely
@ 2011-09-28 15:00 ` Andrew Haley
1 sibling, 0 replies; 5+ messages in thread
From: Andrew Haley @ 2011-09-28 15:00 UTC (permalink / raw)
To: gcc-help
On 09/28/2011 12:41 AM, Jeffrey Walton wrote:
>
> What is the preferred way to tame the optimizer when two class
> functions are producing incorrect results?
I wouldn't. I'd try to isolate the problem into a test case that
demonstrates the problem.
Andrew.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-09-28 8:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-28 5:01 Question on Taming the Optimizer Jeffrey Walton
2011-09-28 6:15 ` Jonathan Wakely
2011-09-28 7:37 ` Jeffrey Walton
2011-09-28 14:36 ` Jonathan Wakely
2011-09-28 15:00 ` Andrew Haley
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).