<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60009>60009</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
x86 backend does not generate optimal code for shl
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lucic71
</td>
</tr>
</table>
<pre>
Hi,
Given the following IR:
```
define i32 @f(i32 %a, i32 %b) {
%shift = shl i32 %a, %b
%cmp = icmp uge i32 %b, 32
%r = select i1 %cmp, i32 0, i32 %shift
ret i32 %r
}
```
the generated code by the x86 backend is:
```
f: # @f
mov ecx, esi
shl edi, cl
xor eax, eax
cmp esi, 32
cmovb eax, edi
ret
```
as per https://gcc.godbolt.org/z/xsY3jqjMn. The respective IR does not trigger Undefined Behavior as demonstrated by https://alive2.llvm.org/ce/ so the optimized version of the x86 code should be:
```
f:
mov ecx, esi
shl edi, cl
mov eax, edi
ret
```
Lucian
cc @nunoplopes
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVEFvozoQ_jXmMmoEQwLhwKFtxHuV3rtUu4c9GnsC7hrM2oam_fUrDEnTardarRURMzOfZ-b7BnPnVNMTlWx3x3aHiI--NbbUo1AiT6LayJfyX8XwnsUHFt8uz3_URD34luBotDbPqm_g4ZGlq5tl8foLr5KOqidQKQLbxkeG-7DFHWd4D-u-ZlgAy-8WCMwm16qjB5YewLUarjEh_i1QdEMIU_NmbOjqzHtI8SrSLseRJuFBJSv4XEZ8VU9IfkZa8me7XVvMD7_sdXnOzDTUk-WeJAgjCeqXwNdpn0HNxXfqJSj3O8aOLL2FP1oM04XUpdLOTMFM4jT3Qk6dW1jWTGTwy1lSEPq9-2Ts4uYLnJ9W_0xscDj1ntNlic5M9RVOntNa8p_QxB0MZKH1fghUYMWwaoTYNEbWRvuNsQ3D6pVhdXLf0qcfT__3G_jSElhyAwmvJoKHR5CGHPTGg7eqacjC136ZOQl31PJJGQvcgaTO9M4votQvH_JyrSbCjdZTt-YVxLACZ4JwZvCqU68kYSLrlOnBHC-KBoVda0YtoabPVH3P29_KdcF95Htdn9P-3ygU768tQsxD1I-9GbQZyEEky1QWacEjKpMsTzMs8iKL2jIRmOw45gL3-X4f59k2Q0SeJUWWyAQpUiXGmMZJkiZ5XOx2G7lNE55SKout2HLB2Tamjit9YTpSzo1UZnEcF5HmNWkXLiPEnp4hOBnifDfZcsbc1GPj2DbWynn3dopXXlN5_X1dxuL8KS4icr3odTR2JjgarS4_jKDy7VhvhOkYVnOC9e9msOaJhGdYhbIcwyqU_TMAAP___o14UQ">