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

            Bug ID: 39109
           Summary: constexpr fibonacci is not computed at compile time
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]

constexpr uint32_t fib(const uint32_t n) {
  if (n <= 1) return 1;
  return fib(n - 1) + fib(n - 2);
}

int main() {
  return fib(7);
}

int main2() {
  const uint32_t res = fib(7);
  return res;
}

Clang is unable to compute fib in main (but it can in main2) at compile time,
GCC can do it in both functions.

main:                                   # @main
        mov     edi, 7
        jmp     fib(unsigned int)    


While main2 is interesting.. Clang computes it as 21 but then it still calls
fib uselessly.

main2():                              # @main2()
        push    rax
        mov     edi, 7
        call    fib(unsigned int)
        mov     eax, 21
        pop     rcx
        ret


Latest GCC:
main:
        mov     eax, 21
        ret
main2():
        mov     eax, 21
        ret

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to