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 8857749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:40:02+00:00 2026-06-14T14:40:02+00:00

In the gcc 4.4.6 docs it is stated: -funroll-all-loops: Unroll all loops, even if

  • 0

In the gcc 4.4.6 docs it is stated:

-funroll-all-loops:
Unroll all loops, even if their number of iterations is uncertain 
when the loop isentered. 

I am compiling this code:

int unroll(){
  int i = 0;
  int array[1000];
  do {
    use(i,array);
    i++;
  }while(i<1000);
  return(0);
}

void use(int i, int *array){
   int x = i*5;
   array[i] = x;
}

…once with the funroll-all-loops optimizations, once without:

OPT = -funroll-all-loops
NOOPT = -O0

Then I use diff to compare the assembly code of each (produced using -S -fverbose-asm).

The produced code is identical.

Tried changing the loop to a do while;
adjusting the loop counter (up to 100);
changing the statements within the loop body.

What could I be missing? Why is this loop not being unrolled?

Update

Nikos C suggested to raise the loop enroll parameter using --param max-unroll-times=N where N is the upper limit.
While that was a sensible suggestion, it did not change behaviour.
I also lowered the loop iterations to only 10.
Also updated the code to actually ‘do’ something, no change.

  • 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-06-14T14:40:03+00:00Added an answer on June 14, 2026 at 2:40 pm

    Because you have disabled all other optimizations in your “OPT” case, you tell to compiler to unroll all loops and then deny him the means to do so, like loop induction etc. Try

    NOOPT = -O2
    OPT = -O2 -funroll-all-loops
    

    If I translate the snippet (changed slightly to an extern function to avoid any inlining and dead code elimination)

    void use(int i, int *array);
    
    int unroll(){
      int i = 0;
      int array[1000];
      do {
        use(i,array);
        i++;
      }while(i<1000);
      return(0);
    }
    

    with gcc -O2 -funroll-all-loops test.c -o test2.o -c, the resulting object code
    is unrolled eight times:

      0000000000000000 <unroll>:
      0:   53                      push   %rbx
      1:   31 db                   xor    %ebx,%ebx
      3:   48 81 ec a0 0f 00 00    sub    $0xfa0,%rsp
      a:   66 0f 1f 44 00 00       nopw   0x0(%rax,%rax,1)
      10:   89 df                   mov    %ebx,%edi
      12:   48 89 e6                mov    %rsp,%rsi
      15:   e8 00 00 00 00          callq  1a <unroll+0x1a>
      1a:   8d 7b 01                lea    0x1(%rbx),%edi
      1d:   48 89 e6                mov    %rsp,%rsi
      20:   e8 00 00 00 00          callq  25 <unroll+0x25>
      25:   8d 7b 02                lea    0x2(%rbx),%edi
      28:   48 89 e6                mov    %rsp,%rsi
      2b:   e8 00 00 00 00          callq  30 <unroll+0x30>
      30:   8d 7b 03                lea    0x3(%rbx),%edi
      33:   48 89 e6                mov    %rsp,%rsi
      36:   e8 00 00 00 00          callq  3b <unroll+0x3b>
      3b:   8d 7b 04                lea    0x4(%rbx),%edi
      3e:   48 89 e6                mov    %rsp,%rsi
      41:   e8 00 00 00 00          callq  46 <unroll+0x46>
      46:   8d 7b 05                lea    0x5(%rbx),%edi
      49:   48 89 e6                mov    %rsp,%rsi
      4c:   e8 00 00 00 00          callq  51 <unroll+0x51>
      51:   8d 7b 06                lea    0x6(%rbx),%edi
      54:   48 89 e6                mov    %rsp,%rsi
      57:   e8 00 00 00 00          callq  5c <unroll+0x5c>
      5c:   8d 7b 07                lea    0x7(%rbx),%edi
      5f:   48 89 e6                mov    %rsp,%rsi
      62:   83 c3 08                add    $0x8,%ebx
      65:   e8 00 00 00 00          callq  6a <unroll+0x6a>
      6a:   81 fb e8 03 00 00       cmp    $0x3e8,%ebx
      70:   75 9e                   jne    10 <unroll+0x10>
      72:   48 81 c4 a0 0f 00 00    add    $0xfa0,%rsp
      79:   31 c0                   xor    %eax,%eax
      7b:   5b                      pop    %rbx
      7c:   c3                      retq   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to the gcc docs , memcmp is not an intrinsic function of GCC.
I've been looking at the GCC docs for defining macros and it looks like
I am compiling MongoDB from source with instructions from http://www.mongodb.org/display/DOCS/Building+for+Linux I ran into this
GCC is a very well respected multi-language compiler (from what I've gathered). One thing
gcc I am just getting back into c programming and I am just practicing
GCC's recent support for atomic operations (as described here ) is great, and is
gcc 4.4.2 c89 I have a wave file: 8000 Hz 16 bit I am
gcc 4.4.2 I have the following code: char channels[] = NumberOfChannel = [2]; sscanf(channels,
gcc 4.4.2 / Visual Studio C++ 2008 I have been using cmake on linux,
GCC seem to think that I am trying to make a function call in

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.