<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/147449>147449</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[InstCombine][TBAA] Miss optimization for check redundancy load
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:optimizations,
llvm:instcombine,
missed-optimization,
TBAA
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hstk30-hw
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/b6vfG688K
```
typedef long int intptr_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
typedef unsigned long int uint64_t;
typedef struct {
union {
uint8_t u6_ucaddr[16];
uint16_t u6_usaddr[8];
uint32_t u6_uladdr[4];
uint64_t u6_ulladdr[2];
} u6_addr;
} In6Addr;
struct policy_match_cond {
In6Addr src_ipv6;
In6Addr dst_ipv6;
};
typedef struct mbuf {
void *userdata;
} __attribute__((__aligned__(64))) Mbuf;
typedef struct {
In6Addr src_ip;
In6Addr dst_ip;
} __attribute__((__aligned__(64))) MbufContext;
void test(Mbuf *mbuf, struct policy_match_cond *condition)
{
(condition->dst_ipv6.u6_addr.u6_uladdr)[0] = ((((((((MbufContext *)((mbuf))->userdata))->dst_ip).u6_addr.u6_uladdr)[0])&0xFF000000) >> 24);
(condition->dst_ipv6.u6_addr.u6_uladdr)[1] = ((((((((MbufContext *)((mbuf))->userdata))->dst_ip).u6_addr.u6_uladdr)[1])&0xFF000000) >> 24);
}
```
Clang is one more load than GCC.
The primary cause maybe clang not handle union's TBAA, like issue https://github.com/llvm/llvm-project/issues/146652.
But in this case, we might be able to delete the second load in InstCombine step :)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVU2P4ygQ_TXkUuoI4--DD07SGY1WfZu7hYHEbNsQmXJmMr9-Bc6Hu1fZz8O0aFmpehTvPUoFd04fjVIVSTck3a34hJ0dq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