<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/101164>101164</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Incorrect Transformations in InstCombine due to TypeBasedAliasAnalysis
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
vedantparanjape-amd
</td>
</tr>
</table>
<pre>
Type Based Alias Analysis emits metadata nodes in the frontend, and an analysis pass in the middle-end does access tag matching to determine if two pointers alias or not. TBAA metadata is only attached to Load and Store Instructions.
But with the enhanced struct path TBAA (enabled by -new-struct-path-tbaa), the TBAA nodes are also added to memory aggregates that might cause two pointers to aliase due to their semantics. So, memcpy is usually tagged with TBAA nodes. This happens here in the Clang frontend.
https://github.com/llvm/llvm-project/blob/bd6e324b67cdadde2593327753e99782146d9bf8/clang/lib/CodeGen/CGExprAgg.cpp#L2200)
Even though memcpy is tagged with TBAA metadata nodes, the TypeBasedAliasAnalysis is not able to correctly find Alias Sets due to the TBAA node structure being slightly different. I have two testcases where AA returns NoAlias for a case with a Load and Memcpy when they actually are Alias/MayAlias.
Reproducer: https://godbolt.org/z/7vK714zWx
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVE1v2zgQ_TX0ZWBDpuQPHXRQ0roItt3DJsCeR-RIYkGRAjmyq_76BaUkbnb30otJQ_Px5r3HwRhN54gqcXgQh08bnLj3obqSRscjBnTfcaQtDnrTeD1XL_NI8ICRNNTWYITaoZ2jiUCD4QgDMWpkBOc1RTAOuCdog3dMTgv5COg0oAN8yxsxvscNRmtLW3IatKcIqBTFCIwdDMiqN64D9qCJKQzGEZgW-OZh9MYxhQi4YPIBnOcdvDzU9R2RieCdnQGZUfWkU6WvHvWC6Jl9IHhykcOk2HgXdyL7JLJ6_X2YGG6G-wUluR6dIg1rMIzI_dpLyDM5bCxpaGbYOrpt15htitlygy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