|
Boost : |
From: Rob Stewart (stewart_at_[hidden])
Date: 2005-10-03 15:22:47
From: brangdon_at_[hidden] (Dave Harris)
> In-Reply-To: <200509282055.j8SKtbXI017230_at_[hidden]>
> stewart_at_[hidden] (Rob Stewart) wrote (abridged):
> > if (!e)
> > {
> > BOOST_ASSERT(false);
> > __assume(false);
> > }
> >
> > The optimizer can't elide the entire else clause because
> > BOOST_ASSERT(false) is in it.
>
> Do you agree that if the code was:
>
> int x = 0;
> if (!e) {
> ++x;
> __assume(false);
> }
> cout << x;
>
> then the compiler can elide the increment?
No.
Having said that, do let me explain that I have *no* experience
with __assume(). I am working only from the previously linked
documentation and intuition.
> At this stage I am trying to convince myself that you understand the point
> I was making, whether or not you agree with how it applies to
> BOOST_ASSERT. __assume(false) can have retrospective effects.
If it can, indeed, apply retroactively, as I think you meant,
then I'm thoroughly confused as to how it works and how one can
apply it consistently.
To my way of thinking, it tells the optimizer than any code
following the directive, until the end of the scope, can be
optimized assuming the condition holds. I can't imagine how the
optimizer could safely assume that the condition holds throughout
the scope in which it appears, including previous to the
directive, but compiler magic can often do wondrous things!
(Note that __assume(false) is useless, for it is an expression
that the optimizer cannot use to optimize anything. So, while I
understand that you were trying to simplify things for the
discussion, let's also not lose sight of what is really meant
when writing __assume(false) in the above examples.)
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk