<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/55003>55003</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
likely wrong code bug from arm64 backend with global isel enabled
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
regehr
</td>
</tr>
</table>
<pre>
here's a function that's part of the LLVM unit test suite:
```
; ModuleID = 'file-020267.bc'
source_filename = "/home/regehr/llvm-project/llvm/test/Transforms/InstCombine/fsh.ll"
target triple = "arm64-apple-macosx12.0.0"
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
declare i32 @llvm.fshl.i32(i32, i32, i32) #0
define i32 @fshl_undef_shift_amount(i32 %x, i32 %y) {
%r = call i32 @llvm.fshl.i32(i32 %x, i32 %y, i32 undef)
ret i32 %r
}
attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
```
here's the output we get from LLVM 14 and also top of tree:
```
Johns-MacBook-Pro:~ regehr$ llc foo.ll -global-isel -march=arm64 -o -
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 12, 0
.globl _fshl_undef_shift_amount ; -- Begin function fshl_undef_shift_amount
.p2align 2
_fshl_undef_shift_amount: ; @fshl_undef_shift_amount
.cfi_startproc
; %bb.0:
mov w8, #32
udiv w9, w8, w8
msub w9, w9, w8, w8
sub w8, w8, w9
lsl w9, w0, w9
lsr w8, w1, w8
orr w0, w9, w8
ret
.cfi_endproc
; -- End function
.subsections_via_symbols
Johns-MacBook-Pro:~ regehr$
```
this function, called with arguments (0, 4) returns 4, which is not one of the permitted outputs given how undef works. unless we're missing something, permissible outputs are 0, 1, 2.
here's the driver I'm using:
```
#include <stdio.h>
unsigned fshl_undef_shift_amount(unsigned, unsigned);
int main(void) {
unsigned z = fshl_undef_shift_amount(0, 4);
printf("%u\n", z);
return 0;
}
```
and the output:
```
Johns-MacBook-Pro:~ regehr$ clang foo.s foo.c
Johns-MacBook-Pro:~ regehr$ ./a.out
4
Johns-MacBook-Pro:~ regehr$
```
this was found using a highly preliminary version of alive2 that does translation validation for the arm64 backend.
cc @nunoplopes @nbushehri @ryan-berger
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVslu4zgQ_Rr7QkhQJK8HH2InATLoAHMIBnMTKImyOKFIgYsd99fPIyVbTqYdBI0xEorrq2Lx1VKo6rRpmGaTdGkIJbWTpeVKEttQG-Y6qi1RNSYY-fHjrxfiJLfEMmOJcdyySXY_SR4myf1kkQx__TDbkhdVOcGeH8gkw3-6rLlgUZIm6WIZFyUm-q1GOV2y3K9K2rJhdzpJnxrVQrMnzfas0egIcWijTqt_WGmHIT5eGXxeNZWmVro1GDxLY3eqLbj0ALVpYiE8Zq9baC3Ve4araN6Ji1Cq28Usoh2mopaWyrzfpXESJ5_O-ts9nW11b602sAORqtaM4WNOssTHySOXFdGMVlJJRkzHSieopQUEHrkQmlmnZQ9ZsVJQzQjPUjKZJf5uMfQWMSYm6Sq0O3L9WUPhLLlWq2I1LnyG8KdzJzGZm4bXNqctVLI9GM7O3wco3z8FvOW2ByJ-SgejlFSIL5T6BU7fD4IBegbEXc979KDz8uFaeQoz8sLhNcO9-hdZbn_XqmSE_8TM0F5I74mtnO2cJUdGPCNqrdqe63czQiGKCqOIVV3wA-hyi_N_qEaa6IWWW6Xeoj-18huXj-TM3xkRoiS1UiAjifZCFVRE3DAMWqrLBjcO_CORItFZ2XVsWOAZunn--vj3Kyyc55a94yV3gMbdgb3rnGY5B-21C9vNCFA4Lqr8wLTxdA209q90F6iUjPu8RsKLucEcMvw8-6OIbNmeyzFk3KLbBb5LqeB7f4_Bl27J8b708eclfsHoi4iy5rmBY1sEiXJ0VXCuKODEl3dL1q06oD2uvAlAt-zi3mtX8bC09kv9BrSXc8YV4-qv9wxbVleL68uiMGI8n_xnUY8n7z7BKh0Wkw-Sz4sg_UczMFmNRiDf_A0v-wjSn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