<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123239>123239</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Unnecessarily large constant created from reordering add and shift
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
dzaima
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/xoKf6bnTb
The code:
```c
#include<stdint.h>
#include<stdbool.h>
bool foo(uint64_t x) {
uint16_t tag = x>>48;
return tag>=0b1111111111110010 && tag<=0b1111111111110100;
}
```
with `-O3` as of clang 19 (and still in trunk) compiles to:
```asm
foo:
movabs rax, 3940649673949184
add rax, rdi
shr rax, 48
cmp eax, 3
setb al
ret
```
whereas 18.0 did this, which is strictly better (i.e. is the exact same set of instructions, just in a different order and without movabs):
```asm
foo:
shr rdi, 48
add edi, -65522
cmp edi, 3
setb al
ret
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMlMGS4ygMhp9Gvqg6hcFx7IMPme7JZQ97mT1PYVBsZjGkQO5Oz9Nv4WR3Uz1zaCpVJPp_CfTFss7ZTYFogP0X2L9UeuU5psH-1G7R1Rjt-zAzXzKoI8gTyNMU7Rg972KaQJ5-gjxd4x_ndgzfRhBHEMdvM6GJlkqGOEIrbh9TfkjlgvFrEZ8zWxd4N4P6-htpjNH_q5XveI4RZLe6wG3znfEKskc4fAFxRCzRuv3OyHpCUC94LYnqa9OBujkS8ZpC0TflRYz1wxKiFgiyBdneLM-_WmohbsXg8PLYF4jjm-MZoRVPfypoBeqM8YzG6zBh3SPITgeLmZ336AJyWsPf5fYmLhfnKSPHD6x0XkAcS8dbHO9ria96zIhJX0E-o-ob0TZ9e1B909ddU5za2s16tyTrHvLznB7FpnvQzHLZdrrXLlImHktM-wdjIv7Y_kyJdMa62wm0ziLPLpcib7MzM7qMmZMz7N9xJGZKBYnb0a5IPBPSVRvGrBcqRxZ4LmROq2EXw1bpx5q5sNNo3flMiQJjTJYSFrSFf1z5zgdk_zmc_-Gw7hcchSPd4k_tfi_l71DddPVY8hPEKjso26teVzTUB3UQ-75t9tU8yE6e69aQMO3Yq74znSTR6Jpq1TRWN5UbpJB7UdetFKoRzc4IUmo0ndgf-iJBI2jRzu-8f13KhFYu55WGWiqp-srrkXzeJl3KQG-4qSBlGfw0lKSncZ0yNMK7zPn_MuzY0_BXCGQoZ52cf0ev01QmPWTWgdEk0kwWzykumGj7d1yYNpLb8z-7M1dr8h_fJ47nddyZuIA8lQPv29MlxR9kGORpu2YGebr38TrIfwIAAP__PNdbng">