[llvm-bugs] [Bug 50412] New: Excessive unrolling/vectorization and ignored assumption for factorial

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 19 22:38:41 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50412

            Bug ID: 50412
           Summary: Excessive unrolling/vectorization and ignored
                    assumption for factorial
           Product: tools
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: opt
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm at rifkin.dev
                CC: llvm-bugs at lists.llvm.org

LLVM is generating suboptimal code for a simple factorial function due to
excessive unrolling/vectorization. https://godbolt.org/z/fPazKsEsn.

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

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.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210520/a2ad1af4/attachment.html>


More information about the llvm-bugs mailing list