<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117724>117724</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
SimplfyCFG removes needed path of computed goto
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
FlameTop
</td>
</tr>
</table>
<pre>
We have determined a case where required code in a computed goto flow is removed incorrectly. The included source has been cut-down from a more complex example and appears to be the simplest we can create to reproduce the fault. In the code the [0]th part of the computed goto is removed and replaced by the [2]nd path of the goto (can be determined by the the constant -0XDEADBEEF being absent from the assembly output).
It appears the commit
@
> commit fc6bdb8549842613da51b9d570b29e27cc709f69
Author: XChy <xxs_chy@outlook.com>
Date: Sat Oct 28 17:10:20 2023 +0800
[SimplifyCFG] Reland transform for redirecting phis between unmergeable BB and SuccBB (#68473)
Reland #67275 with #68953 resolved.
introduced this regression.
Small.CPP: '-S -O2' will reproduce.
```
#typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef short int int16_t;
typedef unsigned int uint32_t;
typedef int int32_t;
typedef unsigned long long uint64_t;
using u8 = uint8_t;
using s16 = int16_t;
using u16 = uint16_t;
using s32 = int32_t;
using u32 = uint32_t;
union u128 {
struct
{
uint32_t w0, w1;
uint32_t w2, w3;
};
struct
{
uint64_t d0;
uint64_t d1;
};
};
namespace IDX{
enum _enum_t : u8
{
x0 = 0,
x1, x2,
x3, x4, x5,
Invalid,
};
}
template< typename T >
union eState_t
{
struct
{
T x0, x1, x2,
x3, x4, x5;
};
T m_r[IDX::Invalid];
};
using Pack128 = u128;
using eState128 = eState_t<Pack128>;
struct State
{
eState128 sdta;
};
void qaz(uint8_t *mem, State &__restrict data){
uint32_t switchval = ~0;
data.sdta.m_r[(IDX::x5)].d0 = data.sdta.m_r[(IDX::x3)].d0;
switchval = data.sdta.m_r[(IDX::x2)].d0;
static constexpr void *switchdispatch[] = {
&&L10,
&&L20,
&&L30,
&&L40,
};
goto *switchdispatch[switchval];
return;
L10:
data.sdta.m_r[(IDX::x3)].d0 = 0xDEADBEEF;
goto L200;
L20:
if (auto reason = (data.sdta.m_r[(IDX::x1)].d0) == (data.sdta.m_r[(IDX::x0)].d0); (data.sdta.m_r[(IDX::x1)].d0 = (0x005b << 16)), reason) { goto L100; };
if (auto reason = (0 == 0); (data.sdta.m_r[(IDX::x3)].d0 = (int32_t((data.sdta.m_r[(IDX::x1)].w0) + 0x5d00))), reason) { goto L200; };
L30:
data.sdta.m_r[(IDX::x1)].d0 = (0x005b << 16) ;
if (auto reason = (0 == 0); (data.sdta.m_r[(IDX::x3)].d0 = (int32_t((data.sdta.m_r[(IDX::x1)].d0) + 0x5d40))), reason) { goto L200; };
L40:
if(auto reason = ((data.sdta.m_r[(IDX::x1)].d0) != ( 0 )); reason) { (data.sdta.m_r[(IDX::x3)].d0 = (s32)((s32 &)mem[(u32)(((IDX::x5)) + (0x398))])); goto L200; };
L100:
data.sdta.m_r[(IDX::x1)].d0 = (0x005b << 16);
data.sdta.m_r[(IDX::x3)].d0 = data.sdta.m_r[(IDX::x1)].w0 + 0x5ce0;
L200:
if(auto reason = ((data.sdta.m_r[(IDX::x3)].d0) == ( 0 )); data.sdta.m_r[(IDX::x1)].d0 = ((data.sdta.m_r[(IDX::x3)].d0) + 0), reason) { goto L300; };
data.sdta.m_r[(IDX::x2)].d0 = (uint32_t)(uint32_t((u16)((s16 &)mem[(u32)(( data.sdta.m_r[(IDX::x3)].d0) + (0xa))])));
L300:
return;
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWElv67oV_jX05iAGRWrywgs7TooAF3gXTYDeXUCRx5b6NF2Sip0u-tsLUoOnJHDaLh5gKBLPwO98_DhFGFPsasQlidYk2sxEZ_NGLx9LUeFL086yRr0v_4GQizcEhRZ1VdSoQIAUBmGfo0bQ-LsrNCqQjUIoamdtqrazqGDX2Aa2Z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