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isg4afS-Vnej7TL9UDYrkl8efshhxojMdxk07ekF8s1glHasYM4Up-dsUttC5YqjL0LxmiDrai6m0MPiVIiTNdy8m-oztRPpiVoOFvDcSAbspgDwkr2k3yd5KtkJSaixSls1q-YnsMOjpPWVOuDc42lOvlElYi2TUMMGRe-gt3PFFvuL8hw0O8HoPt5wlfLyWEd87zIkmI5zyCfZzyOU57jO58uF4sZXyXxxJOXXSMbBJwrOHWx4n9kgcmPI5BrHnEexfEqns1ncRTOs9VsnsVPkK6SRZxGSMlQC1mFZCfUppyYtTeZtqXFw0paZ6-H2JOyVAAeMCJ00lWw9vfG4YXzfdGAKbSpiYAagOagkcHG9xuc_azoW9lOPOi1R_wvd3gN2Q>53297</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLVM crashes when performing peephole optimisation on functions
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
MunchDev
</td>
</tr>
</table>
<pre>
Context:
- MacOS 12.1
- LLVM installed via `brew`
- Output of `llvm-config --version`: `13.0.0`
C++ sample code is `fib(n)`:
```
int a(b) {
if (b < 3) return 1;
else return a(b-1)+a(b-2);
}
```
IR printed by calling `func->print(llvm::outs())` (without optimisation):
```
define double @a(double %b) {
entry:
%cmp_lt_tmp = fcmp ule double %b, 3.000000e+00
%bool_tmp = uitofp i1 %cmp_lt_tmp to double
%if_cond = fcmp one double %bool_tmp, 0.000000e+00
br i1 %if_cond, label %then, label %else
then: ; preds = %entry
br label %if_cont
else: ; preds = %entry
%sub_tmp = fsub double %b, 1.000000e+00
%0 = call double @a(double %sub_tmp)
%sub_tmp1 = fsub double %b, 2.000000e+00
%1 = call double @a(double %sub_tmp1)
%add_tmp = fadd double %0, %1
br label %if_cont
if_cont: ; preds = %else, %then
%if_tmp = phi double [ 1.000000e+00, %then ], [ %add_tmp, %else ]
ret double %if_tmp
}
```
(I'm writing a custom language so the type is `double`, but it should still crashes if it were an `i`)
When I use `llvm::legacy::FunctionPassManager` and add `llvm::createInstructionCombiningPass()`, the program crashes here:
```cpp
/* ... */
llvm::legacy::FunctionPassManager manager;
/* ... */
manager.add(llvm::createInstructionCombiningPass());
Function *func;
/* ... */
manager.run(*func); // Crashes here
```
The generate IR when compiled to bitcode (with `llvm-as`) and optimised (with `opt -O3`) does not have any issues, so errors in code generation are `likely` ruled out.
Any ideas?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVluP8jYQ_TXhxSLKhVse8sBCkVb6Vlu1Vfu4cpIhcZvYke1A-fedcRIIu4tKpUYIsD0z58wlM85UcUl3Slr423rx1gv2XrCdszeev__KwsgPx50fP35_Y0Iay-saCnYSnHmrINNwxp9R6L2zbWeZOtJZXZ-aea7kUZRsPj-BNkJJEo63dBzGfuAHV-X-e-dFL_hhhjdtDSxXBTBhSPwoMi_aSC9KehOD1ioYPm4ppGUcxVA0Yd76pd9l-AikhPvMi3csplMNttOShV48kYLawHji7MxDAoxe-kVEi1HeW--_5dB_v_7CWo10MFTZheUYNCFL50cn87kX_-RO0SpFidyJt6qzBjccIDlJhM_CVooi2lrRCMMthZBIfO9_AUchgRWqyzB63iIg3uMqWt6HBaTVl6slRgJ5037U9sM2LQZqz464Zl19M-hMYAD9wD2AkQmCiX6mVH3V7oRVx5aJ8JNlqwZ7E0Vx_MBKKW6oSt6hDnYJPPgWPNMD0GCJJGueQU17tgJ5t0F5nmbLCcSuBJ5-sBAwxVAYR5qMunje-FzRekp2CugI_K-AuDZddksdLj6nLXyUtsCpUJE-LJ3BNtXeF8DwIWL0CDF8GjG8h-RFcfMRFxPEgBDJ9pM5GLf-Sxq-5oAS2eO6Iror6ZFoW4krz-XL5zzctPF075YodPN1EHC9iQQGCGxTE-d7tH_pTNHm1YvWDTtrYakdcZZ3xqoGwyTLjpfAjGJIhNlLO_bd4VVdOZ4ZtiJhmcGeVBfMWIH5yzU3FRjqsHh0Bg2MS9IUTimZhvw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