<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJylU9uK2zAQ_Rr5ZUiwpThOHvzQTciysEuhLIU-yvLEVpElV5Kzl6_v2M5mQ1j6UpCty4zOOXNR5eq38hlDBCUDgrawY_yOBjC-CYjA8rt7V1fORJbv6ayNsQ9MfGP8QKOZTUvnG9q90_d8_0vc-yfxh_HtOMgz3bP0479O56H6_nwy4RDbCpSRtjmzL0KsmdirectTWHwXcNQGl0oBXEMqZ0PE196T-EguFYkcV5bYgRV3sxeAPo4hWWBiB_zGBuAxDt7SJXE5ZMX-sjzPZ6-ZxMICsgmI9H4e8SnqM8oFY_5PCsnvhv6cg9jqALXDQNKLCA1GwJM0g4xYQ3SQ51_qyNJ_MN5CX-VMWx2nnEnKyf5rsI9yXUM-twi7sVRw9M7GBdoaqFO6QC3Uy8oguCPoyPgOqoHidR5eWorhhJ6Ey-AsPD7-fAJ9jnO6QuHVbpK5hJEgdNIYkJ0bSCDhRRwFN_AAta7hRceWnBEefoAk-m4wUfcE4wcbRneS7Po4Ng2txiszFVFI-0YshESMUsWBaN4uaSbZSV2Keiu2MpFDbJ0vyWalcq_J4E150_0kY6iWynW0Meb0MS16736johQcdAgDZZ0fciGKPGlLzIr1OqvSopCbjVrJY5qtqkoUFd_wfIubxMgKTSjp3THOLb7ABEFren_J_yvQJU85TzO-SnmWCbGs02Krjlm1FlmxXasVW6XYSW2WI874sBNfTpDV0AQyGh1i-DTKEHRjESfBpDDqaLCcCqzknHXS0qOnNFNJdKffqUyoBh_0CeGgK0fpVXquqYSpNSUVPZmEl5PqvytNYqE>53375</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLVM can't properly optimize recursive Fibonacci with a constant
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
evanacox
</td>
</tr>
</table>
<pre>
Test case in C++ (see [Godbolt](https://godbolt.org/z/TGY3GrM3q)):
```cpp
// $ clang++ -std=c++20 -O3 file.cc
constexpr int fib(int n) {
if (n < 2) {
return n;
}
return fib(n - 1) + fib(n - 2);
}
int f() {
// this doesn't get evaluated to 55
return fib(10);
}
// this does
constinit int a = fib(10);
```
The Clang front-end seems capable of it, but for whatever reason LLVM isn't able to do this. The small amount of testing I did with the IR and multiple runs of `opt -O3` didn't do anything to actually evaluate it
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9U9tuozAQ_RrzMkoENpTwwMM2UapKrVZaVSvtozEOeGVs1jbp5et3MDStoqqSwbeZc84c241tX-sn6QMI7iUoA3tCb7EBoTsvJZDi9s62jdWBFAdc60MYPWE_CD1i65atrXUdzt7we7r7w-7cI_tHaDU3jEwPJH3_36RLE-O4rkQcZMtBaG66lX3jQ0vYQSxTmsLmJ4OT0nIrBMBnSGGND_JldCg-YEiDIueRQXYg5e0SBaBOc0kGCNsDvdoDcDJMzmASuyyS8nAZrv0atZAY2EAWgVDvxxKNVa8oF4zlHxVi3BX96kHolYfWSo_SywCdDCDPXE88yBaChaL4UkeWfsN4Df3JM2VUiJ5x9OTwNdj7cX2GfOol7OejgpOzJmykaQFvyuDxCo280RLsCVQgdA_NhPVaB8891nCWDoVzbw08PPx-BLXWGVOwvNZGmVuYCfzAtQY-2AkFIl6Qs-AO7qFVLTyr0GOwhPtfwJF-mHRQI8K4yfg5HCXbMcyXBkdzykKFFNy8IgsiISMXYUKa14vNKDtpa9ZWrOJJUEHLOkoVfMkfnR2lwwQEV4N6Q0IpJufVWcJRNdZwIdSijkM0maP8ZHK6vno3GDI1W2EHnGh9fu82yPBXCjTvqLyf8LzosWCsLJK-3pVFkxc5p3lWSJaXgld5ntGc8XRXZXyXaN5I7Wt8sYRSI58hQuAYX26iappSmmJ8SrOMsW2blpU4Zc0Ny8rqRuQkT-XAld7OOuYHnbg6SmqmzuOmVj74j03uveqMlJEO8fkUeutqdBJNsC9J5K6j9v8WhkyU">