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: unassignedb...@nondot.org
          Reporter: l...@rifkin.dev
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to