<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71383>71383</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Example of `expr1 ? expr2 : expr3` that consists only of inequality expressions and cannot be simplified by clang
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
k-arrows
</td>
</tr>
</table>
<pre>
Consider the following functions.
https://godbolt.org/z/98EoarhzM
```cpp
// expr1 ? expr2 : expr3 --> expr1
int foo1(int a)
{
return (a < 5) ? (a < 7) : (a < 3);
}
// expr1 ? expr2 : expr3 --> expr2
int foo2(int a)
{
return (a < 7) ? (a < 3) : (a < 5);
}
// expr1 ? expr2 : expr3 --> expr3
int foo3(int a)
{
return (a < 3) ? (a < 5) : (a < 7);
}
```
GCC can simplify these functions. If you rewrite these functions in if-else form as shown below, clang can simplify those.
https://godbolt.org/z/oxjWThe74
```cpp
int bar1(int a)
{
if(a < 5) return (a < 7);
else return (a < 3);
}
int bar2(int a)
{
if(a < 7) return (a < 3);
else return (a < 5);
}
int bar3(int a)
{
if(a < 3) return (a < 5);
else return (a < 7);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyslMFuozwQx59muIwSmXEI4cAhTcun77C3lfZswAR3HZu1zabp06-AtE2aNNtKKyExGtvj34z_M8J7tTVS5pDcQXIfiT601uU_Z8I5u_dRaetDvrHGq1o6DK3Exmpt98psselNFZQ1fg7sHti6DaHzwNdABVCxtXVpdZhbtwUqnoGKbPVghWufv03bYcmmr-q6o2c8iPKpczECnyxC4OvR4jibAX-Y1qcTygRsrI2BVoMpgLJjqPRuMhDRydA7g0ArgcA3mABlY_hXTzp51m8ePkTidy_B7o_GVzHpDJO-hJleYPILzOTfYPIzTP4lTH6BmVxgptcxXwRwSv3fZoOVMOjVrtOqOQya8_JEa_h_gwfbo5N7p4J8v47KoGpmUg9O63YoPPrW7g2WUts90AYrLcz2_SXWy0_K2D49_vjeynTxkYyH2pXC3Ralas7rde31X0uGiGNC12r_0fMfKW5r7oQivUZxdsF1hlsSPDLcFtQJA7_GkHymEn9RWFTnvM54JiKZx8sso5RSlkRtXicLkVXEaLloGr4UGRNpxdJ4FbMmLUseqZwY8Thmy5jieJHMBTVlLbJ4-EliC1gwuRNKz7X-vRtkEinve5mnMV_xSItSaj9OV6JReEA0DFqXD_tnZb_1sGBa-eDfIgQVtMwfnsSu0xJtg7BkH_YxLBmGVgSshjHtg0dr9GE4pYz81QutwmHcKb0fO0SYelC_sQFL-dIDStZYHqbeiHqn83dtoELbl_PK7oCKgfP4m3XOPsoqABVj2h6oGDP_EwAA___assMx">