<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 - Excessive unrolling/vectorization and ignored assumption for factorial"
   href="https://bugs.llvm.org/show_bug.cgi?id=50412">50412</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Excessive unrolling/vectorization and ignored assumption for factorial
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>tools
          </td>
        </tr>

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

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>opt
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>llvm@rifkin.dev
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>LLVM is generating suboptimal code for a simple factorial function due to
excessive unrolling/vectorization. <a href="https://godbolt.org/z/fPazKsEsn">https://godbolt.org/z/fPazKsEsn</a>.

Three levels of unrolling/vectorization seem to be generated: n >= 32, 32 >= n
<span class="quote">>= 8, and n < 8.</span >

Because this function is working with 32-bit ints, anything larger than 12!
isn't particularly useful (20! for 64-bit ints). The n >= 32 level should never
be used.

It would be cool if the compiler could deduce this, but perhaps not possible.

Even with explicitly telling the compiler the domain of the function, clang
still generates the same excessive code.

int f(int n) {
    __builtin_assume(n <= 12);
    if(n <= 0) return 1;
    return n * f(n-1);
}

The n >= 32 level should not be generated given the assumption.</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>