<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62587>62587</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
sext(square nsw) produces unnecessary zext on riscv64/mips64/loongarch64
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sorear
</td>
</tr>
</table>
<pre>
Minimal C reproducer(s):
```c
int a(int x) { return x*x; }
long b(int x) { return x*x; }
```
Expected output (on riscv64, generated with `-fwrapv`):
```
a: # @a
mulw a0, a0, a0
ret
```
What is actually generated:
```
a: # @a
mulw a0, a0, a0
slli a0, a0, 32
srli a0, a0, 32
ret
```
compiler explorer link: https://godbolt.org/z/Yq898xoT1. clang-14 produces the optimal code for a but not for b.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEk0uPpC4UxT8Nbm6qgmBZsnDRj7-7_26SySwRbyszCDaPKrs__QSrX6lkeno3xIBXDnh-hCND0KNFbMnhlhzuC5ni5HwbnEfpi94NT-3_2upZGrgDj4t3Q1LoCWsCYYLwG0LvCX3ta3p51KXWNoIkrMnjSpgAcrwFjzF5m-ublfBbIMf7i9o4O0L_Zfnbzz46-G9dUEUcwKW4pAiENc6C10Gd6oqwOxjRopdZcdZxAlLT3cPZy-WUN_oz0KWUhN_AlxphHEhF5WUdzMmc82dJs4e3_jL50jzGT8C-TzKCDiBVTNKYp3eQf2g5GKOvNZxdafzfNZ-jKzcv2qAHXBfjPHow2v7KXFOMS8j8rCOsG93QOxP3zo-Edc-EdT8eG9Gs7lu5B1BG2nFXVvByhQPECcEtcbvbyg0ID86DhD5FsC5uVb8vhpYPggtZYFvWDa-4EGVZTC3jJa8Y9j2nfT-IB3asUODQVEKUrBei0C2jjNMDPdK6LA90L-qSH1gtFVMNP2JFKoqz1GZvzGnOrgsdQsK2ZofmWBjZowlbLBmzeIZtkjCWU-rbvGbXpzGQihodYnjfJeposA24xpzSxyQ9gg3nHKg39mQtKgxB-id4xjXCx5R0s17C9mKcs6P0aqqrInnTXh24jlPq98rNWWpOr8Nu8e4nqkhYt5kOhHUb1O8AAAD__8zzOdY">