<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60690>60690</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Failed to detect pattern for “llvm.bswap.i64” in some of my test cases with Clang 12, but no such problem with Clang 11
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RKSimon
</td>
</tr>
</table>
<pre>
Reported here: https://discourse.llvm.org/t/failed-to-detect-pattern-for-llvm-bswap-i64-in-some-of-my-test-cases-with-clang-12-but-no-such-problem-with-clang-11/68421
https://godbolt.org/z/7aEjjbeed
Example:
```ll
define i64 @src(i64 %result) {
entry:
%and.i = lshr i64 %result, 8
%shr.i = and i64 %and.i, 71777214294589695
%and1.i = shl i64 %result, 8
%shl.i = and i64 %and1.i, -71777214294589696
%or.i = or i64 %shr.i, %shl.i
%and.i7 = shl i64 %or.i, 16
%shl.i8 = and i64 %and.i7, -281470681808896
%and1.i9 = lshr i64 %or.i, 16
%shr.i10 = and i64 %and1.i9, 281470681808895
%or.i11 = or i64 %shl.i8, %shr.i10
%or.i12 = tail call i64 @llvm.fshl.i64(i64 %or.i11, i64 %or.i11, i64 32)
ret i64 %or.i12
}
declare i64 @llvm.fshl.i64(i64, i64, i64)
define i64 @tgt(i64 %result) {
entry:
%bswap = tail call i64 @llvm.bswap.i64(i64 %result)
ret i64 %bswap
}
declare i64 @llvm.bswap.i64(i64)
```
```ll
define i64 @src(i64 %result) {
%entry:
%and.i = lshr i64 %result, 8
%shr.i = and i64 %and.i, 71777214294589695
%and1.i = shl i64 %result, 8
%shl.i = and i64 %and1.i, -71777214294589696
%or.i = or i64 %shr.i, %shl.i
%and.i7 = shl i64 %or.i, 16
%shl.i8 = and i64 %and.i7, -281470681808896
%and1.i9 = lshr i64 %or.i, 16
%shr.i10 = and i64 %and1.i9, 281470681808895
%or.i11 = or i64 %shl.i8, %shr.i10
%or.i12 = fshl i64 %or.i11, i64 %or.i11, i64 32
ret i64 %or.i12
}
=>
define i64 @tgt(i64 %result) {
%entry:
%bswap = bswap i64 %result
ret i64 %bswap
}
Transformation seems to be correct!
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVstu5DYQ_BrqQnAgUg9SBx28HuuS2yY_QEmtEQ1KHJBUNs7XB9RjPNLOOk6wxwUMy-ZUd1cRXZqSzqnLCFCi7AvKzpGcfG9s-fW339Vgxqg27Vv5Fa7GemhxDxZQ8oR7768OJU-IVYhVrXKNmayDk9Z_DidjL4hVHrGqk0pDS7whLXhoPLlK78GOpDOWBCyp3Td5JSpPiRqJMwMQ05HhjXhwnjTSgSPflO9Jo-V4IZSRevJkNMRNTU-u1tQahh2CIlblImUUxWcUPy2_93Qvpq2N9ivPvxGruHx5fa0B2vuil7_kcNVB7nqax8uP1stBC50aAas8xSiNnW0QE_M_LLPgJu0RKzDiXxY0jN6-3ZrhgJJje1IYJWesXW_xofYZizus6-2KlWO7QecGAckp55zRlBVpJoq8yPZT6Frqev1vU_TDKXQZQ45z8rtasxE0Nykz6VC4tT6K50daZi2g-ZGVeCiez7SYoCmPc0FFLMSO1MK9-O6SfzDHnhSNH-svAnw_KDuop_Q7_YH47QLm7scaNtd4qTRupNbbOs1O6uYGefq-WMuY0PHhQcIQK7YJFvwOxdY95udtfxstLXwwcW17exT3_tivv7_4_7r-s_c_UD9_vpd_a_xA4wz_hMRD23dVm79_it0Ry345_pfjf-z47nAHH7v6k5ZGyRklL__Hn4_39d2iy1_7-s958A8rR9cZO0ivzIgdwOCwN7gG3BhrofHo9m29eS5qy6QtkkJGUNKc52EBBY_6Mq0p5w1wFlMpRFaztqFJxruGiSJJ4i5SJYtZEjPKaBanKT_xOimarBYCZENZlqA0hkEqfcsqkXJugjKP8yKOtKxBuy0L2XIJKdPFhbeHct69l3nlNZTVHHGCniXi4DXi4M5YjF4YEjEqng8vnvX4jNWIQ-jBpsPDGw6hB8-hB4dIg59DpMGUhT2oJ49Hg0PuwWvu2YFoNFldHoKO8v1UnxozIFYFCusjBKfX-d6rWbsLmSnI_ycAAP__Yh29-g">