1748269 Members
3779 Online
108760 Solutions
New Discussion юеВ

Re: O1 and O2

 
SOLVED
Go to solution
Alex Vinokur
Frequent Advisor

O1 and O2

Hi,

HP-UX v2 and v3
aCC: HP C/aC++ B3910B A.06.25.01 [May 16 2010]

For instance, we need to create two libraries: liba.so and libb.so

Library liba.so is built on basis of files a1.cpp, a2.cpp, ..., a1.h, a2.h, ...

Library libb.so is built on basis of files b1.cpp, b2.cpp, ..., b1.h, b2.h, ...

Files b1.h, b2.h, ... include some of files a1.h, a2.h, ...

Question.
Is it correct to compile liba.so with optimize mode O1, but libb.so with optimize mode O2?
Can that cause undefined behaviour (incuding crashing program that uses liba.so and libb.so)?

Thanks

Alex




8 REPLIES 8
mvpel
Trusted Contributor
Solution

Re: O1 and O2

Here's some HP docs about aC++ optimization, which is probably functionally pretty similar to aCC.

The "Level 1 optimzation" is the default, so it seems unlikely that O2 or any other opt level would have any potential to create undefined behavior when used with O1 libs, and if it did it would probably be considered a compiler bug. So my advice would be not to fret about it.

http://docs.hp.com/en/1559/optimize.htm

Level 1 Optimization
Level 1 optimization includes branch optimization, dead code elimination, faster register allocation, instruction scheduling, and peephole (statement-by-statement) optimization. Use +O1 to get level 1 optimization. Level 1 is the default.

Level 1 optimization produces faster programs than without optimization and compiles faster than level 2 optimization. Programs compiled at level 1 can be used with the HP Distributed Debugging Environment (DDE) debugger. Use the debugger option -g0 or -g1.

Level 2 Optimization
Level 2 optimization includes level 1 optimizations, plus optimizations performed over entire functions in a single file. Level 2 optimizes loops in order to reduce pipeline stalls and analyzes data-flow, memory usage, loops, and expressions. Use -O or +O2 to get level 2 optimization.

Specifically, level 2 provides:

* Coloring register allocation.
* Induction variable elimination and strength reduction.
* Local and global common subexpression elimination.
* Advanced constant folding and propagation. (Simple constant folding is done by default.)
* Loop invariant code motion.
* Store/copy optimization.
* Unused definition elimination.
* Software pipelining.
* Register reassociation.

Level 2 can produce faster run-time code than level 1 if programs use loops extensively. Loop-oriented floating-point intensive applications may see run times reduced by 50%. Operating system and interactive applications that use the already optimized system libraries can achieve 30% to 50% additional improvement. Level 2 optimization produces faster programs than level 1 and compiles faster than level 3 optimization.
Dennis Handly
Acclaimed Contributor

Re: O1 and O2

>Is it correct to compile liba.so with optimize mode +O1, but libb.so with optimize mode +O2?

Yes, you can mix and match opt levels.
Do you have any problems or just asking?
Alex Vinokur
Frequent Advisor

Re: O1 and O2

> >Is it correct to compile liba.so with optimize mode +O1, but libb.so with optimize mode +O2?

> Yes, you can mix and match opt levels.
> Do you have any problems or just asking?

We have crashing some program. While investigating we check any thing that can cause the problem.

Thanks
Dennis Handly
Acclaimed Contributor

Re: O1 and O2

>We have crashing some program

Do you have a stack trace where it crashes?
Alex Vinokur
Frequent Advisor

Re: O1 and O2


Callstack is attached.

Dennis, thank you.
Dennis Handly
Acclaimed Contributor

Re: O1 and O2

>Callstack is attached.

Are you in a thread?
You seem to be dying while creating a map<:rostringref> in MT_NBIRefMapping.cpp:50.
Alex Vinokur
Frequent Advisor

Re: O1 and O2

> Are you in a thread?
> You seem to be dying while creating a map<:rostringref> in MT_NBIRefMapping.cpp:50.

The developers try to investigate, localize and reproduce the situation.
When the situation reproduces, the relevent stuff will be send to the forum.

P.S The program is not mine. I was asked to ask of that in HP-forum.

Thank you.

Alex Vinokur
Frequent Advisor

Re: O1 and O2

I didn't receive reproduced crash-situation from my colleagues. It seems that they could not reproduce it.