Open 470e7f89-017b-4dca-8bb4-aa88c7fd5a01 opened 3 years ago
We can probably fix this by turning the shift back into a multiply if it would allow us to remove the recursion. The Reassociate pass does something similar.
Seems to be because the multiply by 2 in bar was turned into a shift by 1. If you change it to a 3, it works.
Extended Description
Of the following simple recursive functions, LLVM is able to eliminate recursion for foo but not bar:
int foo(int n) { if(n <= 0) return 1; return 2 + foo(n - 1); } int bar(int n) { if(n <= 0) return 1; return 2 * bar(n - 1); }
GCC optimizes both. https://godbolt.org/z/rozMcn6o4.