473,396 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Optimization issue with VC7.1

Hi,

consider the following small program created to test
the optimizer:

#include <iostream>

struct X {
X(int i) : i_(i) {}
int i_;
};

class Singleton {
private:
Singleton() : b(true) {};
public:
static Singleton& get()
{
static Singleton s;
return s;
}
bool b;
};

inline void f(const X&) {};

inline void g(const X& x)
{
if(Singleton::get().b)
std::cout << x.i_ << std::endl;
}

int main(int, char**)
{
f( X(42) );

std::cout << "Output? (0/1): ";
int i;
std::cin >> i;
Singleton::get().b = i!=0;

g( X(42) );

return 0;
}

When I look at the code generated in a release build
(/O2), I see that the optimizer completely eliminates
the call to 'f()'. In the call to 'g()' the code first
checks the bool and doesn't do anything if it is false.
(BTW, the decision is done by user input in order to
prevent the optimizer from finding out about it during
compilation.)
So far so good. In reality, I have code that is quite
similar, but much more complicated. Particularly, the
compiler seems to be unable to inline the ctor of 'X'.
Unfortunately, in the call to 'g()', it creates an 'X'
before it checks the bool. I suspect this it needs to
do because if it won't inline 'X's ctors it likely
also cannot proof that the ctor doesn't have any side
effects?
Or is there anything else that might prevent it from
skipping the initalization of arguments that are to
be thrown away?

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett
Nov 17 '05 #1
1 888
Hendrik Schober <Sp******@gmx.de> wrote:
[...]
Or is there anything else that might prevent it from
skipping the initalization of arguments that are to
be thrown away?


Anyone out there knowing?
(This is for a logging lib I am making.
I want to have generated as little code
as possible when logging is turned off.)

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Neil | last post by:
I just resolved a strange situation I was having with an ODBC linked SQL 7 view in an Access 2000 MDB file, and I'm trying to get some understanding as to what happened. The linked view was...
9
by: Rune | last post by:
Is it best to use double quotes and let PHP expand variables inside strings, or is it faster to do the string manipulation yourself manually? Which is quicker? 1) $insert = 'To Be';...
5
by: AC Slater | last post by:
Whats the simplest way to change a single stored procedures query optimization level? In UDB8 that is. /F
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
3
by: Dmitry Jouravlev | last post by:
Hi, I have a number of C++ solutions in Visual Studio .NET and when i compile them using "Whole Program Optimization", certain projects report a LNK1171 error saying that c2.dll could not be...
19
by: Jim West | last post by:
The execution speed of the following code is dramatically faster if I declare some arrays globally rather than locally. That is FOO a, b, c; void bar() { ... } runs much faster (up to...
10
by: SzH | last post by:
The code below demonstrates that the copy constructor of moo is not called on the first line of main. In spite of this, g++ (version 4.1.2) refuses to compile it if I make the copy constructor...
3
wiredwizard
by: wiredwizard | last post by:
So does my site need optimization or marketing? (my response to a recent email from a gentleman asking whether he should optimize or market his website and I was wondering what others think) ...
34
by: jacob navia | last post by:
Hi I am adding an optimization to lcc-win: sqrt(2.0) will provoke now that the constant 1.4142... etc will be generated instead of generating an actual call. Details: -------
20
by: Ravikiran | last post by:
Hi Friends, I wanted know about whatt is ment by zero optimization and sign optimization and its differences.... Thank you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.