Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6064591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:17:48+00:00 2026-05-23T09:17:48+00:00

I recently received a bug report about a program which fails to compile with

  • 0

I recently received a bug report about a program which fails to compile with the -O3 switch (see https://github.com/cschwan/sage-on-gentoo/issues/66). In particular, the problem is that compilation hangs at a certain point. The issue is solved by compiling with -O2 (I am well aware of the fact that programs compiled with -O3 may be broken, but I did not know that -O3 may hangup the compiler). If you want to reproduce the issue run

wget http://perso.ens-lyon.fr/xavier.pujol/fplll/libfplll-3.0.12.tar.gz
tar -xf libfplll-3.0.12.tar.gz
cd libfplll-3.0.12
./configure CXXFLAGS="-O3"
make

I wondered why -O3 hangs up the compiler and so I tried to track down the issue. First, I tried to find out the the difference between -O2 between -O3. Gcc’s man page states that -O3 enables the switches of -O2 and the following ones (lets call them x):

-finline-functions -funswitch-loops -fpredictive-commoning -fgcse-after-reload
-ftree-vectorize -fipa-cp-clone

I verified that by comparing the output of gcc when invoked with -Q -O2 --help=optimizers and -Q -O3 --help=optimizers. I then planned to selectively remove the switches in order to find the one which causes the problem. However, compilation works fine with -O2 and the additional switches above, so I conclude

-O3 != -O2 x

Now my question: Does anybody know if there is a further difference between -O2 and -O3 (undocumented?), has anyone experienced a similar behavior ? Is this maybe a compiler bug ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:17:49+00:00Added an answer on May 23, 2026 at 9:17 am

    Man pages can be outdated, but you can find actual lists for O2 and O3.

    To get full list (almost, check “update”) of -f optimization options actually used, I suggest you use the -fverbose-asm -save-temps (or -fverbose-asm -S) – there is a full list at a top of asm file (*.s).

    For gcc-4.6.0 I got x (the difference between O2 and O3) to be:

     -fgcse-after-reload
     -finline-functions
     -fipa-cp-clone
     -fpredictive-commoning
     -ftree-loop-distribute-patterns
     -ftree-vectorize
     -funswitch-loops
    

    Another source of information for your question is the sources of GCC (file gcc/opts.c and possibly gcc/common.opt) as gcc-4.6.0:

    /* -O3 optimizations.  */
    { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
    { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
    /* Inlining of functions reducing size is a good idea with -Os
       regardless of them being declared inline.  */
    { OPT_LEVELS_3_PLUS_AND_SIZE, OPT_finline_functions, NULL, 1 },
    { OPT_LEVELS_3_PLUS, OPT_funswitch_loops, NULL, 1 },
    { OPT_LEVELS_3_PLUS, OPT_fgcse_after_reload, NULL, 1 },
    { OPT_LEVELS_3_PLUS, OPT_ftree_vectorize, NULL, 1 },
    { OPT_LEVELS_3_PLUS, OPT_fipa_cp_clone, NULL, 1 },
    

    I have also checked, does gcc check -On in other files (cscope symbol search for x_optimize).

    The only additional usage of n from option -On is saving it value into macro __OPTIMIZE__. So some headers can behave differently for value of this macro equal 2 or 3.

    UPDATE: There are questions about it in GCC WIKI:

    • “Is -O1 (-O2,-O3 or -Os) equivalent to individual -foptimization options?”

    No. First, individual optimization options (-f*) do not enable optimization, an option -Os or -Ox with x > 0 is required. Second, the -Ox flags enable many optimizations that are not controlled by any individual -f* option. There are no plans to add individual options for controlling all these optimizations.

    • “What specific flags are enabled by -O1 (-O2, -O3 or -Os)?“

    Varies by platform and GCC version. You can get GCC to tell you what flags it enables by doing this:

    touch empty.c
    gcc -O1 -S -fverbose-asm empty.c
    cat empty.s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've recently received a bug report for my software not compiling on a MacOS
Recently, we received a bug report from one of our users: something on the
I recently asked a question about functional programming, and received (good!) answers that prompted
I recently received a comment on one of my blog posts about JSLint asking
I recently received a feedback from a colleague about my source code of a
One of our site recently received a lots of attack which all seems similar.
We recently received a report that our application will occasionally fail to run. I
I recently received an email from my girlfriend that spamassassin marked as spam, mostly
I recently received a project that contains multiple web applications with no MVC structure.
I'm using subclipse in Flex Builder 3, and recently received this error when trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.