<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/111093>111093</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
ReplaceWithVeclib constructs scalar overload intrinsic name incorrectly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tex3d
</td>
</tr>
</table>
<pre>
The ReplaceWithVeclib (replace-with-veclib) pass constructs the scalar overload name used to look up the veclib call by passing all the input argument types (converted to scalar) to `Intrinsic::getName`.
https://github.com/llvm/llvm-project/blob/e9b7a093417bda7e0bed2bd62bcaeb7c2a662665/llvm/lib/CodeGen/ReplaceWithVeclib.cpp#L132
This is incorrect. Instead, it should be using `isVectorIntrinsicWithOverloadTypeAtArg` to determine whether an argument type contributes to the overload, including the return argument (-1).
This mostly went unnoticed because most intrinsics supported so far only had one argument, and that argument type matched the return type. For other intrinsics, such as `pow` or `atan2` with two arguments, this would construct a name like `llvm.pow.f64.f64`. This won't match the name in the table defined in `VecFuncs.def`, causing it to fail replacement silently.
There is a note in `llvm/test/CodeGen/AArch64/replace-with-veclib-armpl.ll` noting the bug above the `llvm.pow` checks, and the checks were written to match the input (no translation). I didn't see the note until I debugged the pass after running into the bug while trying to implement this for `atan2`.
https://github.com/llvm/llvm-project/blob/e9b7a093417bda7e0bed2bd62bcaeb7c2a662665/llvm/test/CodeGen/AArch64/replace-with-veclib-armpl.ll#L337-L340
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVc1u6zYTfRp6M7AgU4ocLbTwdy_84QIXLVAE6Zo_Y4sNTQrkyK7fvhjKSZykm3ZTILHNv5kz55whVc7uGBAH8fA_8fB9pWYaYxoI_2zsSkd7HZ5GhN9w8srg747GZzTeaRDyMS2T64ujcX0u00L2MKmcwcSQKc2GMtCIkI3yKkE8Y_JRWQjqhDBntEARfIwvME9l4xIGjPIe9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