<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - The loop will not be unrolled by writing the -fno-unroll-loops option before or after -O2."
   href="https://bugs.llvm.org/show_bug.cgi?id=47033">47033</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>The loop will not be unrolled by writing the -fno-unroll-loops option before or after -O2.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>fj8765ah@aa.jp.fujitsu.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>a.c:

void foo(double * restrict a,
         double * restrict b,
         double * restrict c,
         int n) {

  for (int i=0;i<n;i++)
    c[i] = a[i] + b[i];

  return;
}


The loop will not be unrolled by writing the -fno-unroll-loops option before or
after -O2.
# For AArch64, this problem does not occur unless the -mcpu option is
specified, for example, thunderx2t99.


% clang -target x86_64-unkown-linux-gnu -O2 a.c -Rpass=unroll -S
a.c:6:3: remark: unrolled loop by a factor of 2 with run-time trip count
[-Rpass=loop-unroll]
  for (int i=0;i<n;i++)
  ^
% clang -target x86_64-unkown-linux-gnu -fno-unroll-loops -O2 a.c -Rpass=unroll
-S
% clang -target x86_64-unkown-linux-gnu -O2 -fno-unroll-loops a.c -Rpass=unroll
-S


However, the loop is not vectorized only if the -fno-vectorize option is
written after -O2.

% clang -target x86_64-unkown-linux-gnu -O2 a.c -Rpass=vector -S
a.c:6:3: remark: vectorized loop (vectorization width: 2, interleaved count: 2)
[-Rpass=loop-vectorize]
  for (int i=0;i<n;i++)
  ^
% clang -target x86_64-unkown-linux-gnu -fno-vectorize -O2 a.c -Rpass=vector -S
a.c:6:3: remark: vectorized loop (vectorization width: 2, interleaved count: 2)
[-Rpass=loop-vectorize]
  for (int i=0;i<n;i++)
  ^
% clang -target x86_64-unkown-linux-gnu -O2 -fno-vectorize a.c -Rpass=vector -S
%

I think it is because I did not check the positional relation with -O2 in
clang/lib/Driver/ToolChains/Clang.cpp.
I think -fno-unroll-loops should behave like -fno-vectorize.
How do you like it?</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>