<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - LLVM 12 regression: AArch64 backend generates incorrect code for f32 to i128 conversion"
href="https://bugs.llvm.org/show_bug.cgi?id=49710">49710</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>LLVM 12 regression: AArch64 backend generates incorrect code for f32 to i128 conversion
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: AArch64
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>amanieu@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>arnaud.degrandmaison@arm.com, llvm-bugs@lists.llvm.org, smithp352@googlemail.com, Ties.Stuij@arm.com
</td>
</tr></table>
<p>
<div>
<pre>This bug was found while running the tests for
<a href="https://github.com/rust-lang/compiler-builtins">https://github.com/rust-lang/compiler-builtins</a> after rustc upgraded to LLVM 12.
The issue can be reproduced with Clang (-O0 only):
unsigned bad(float num) {
return (__uint128_t)num;
}
The assembly uses fcvtzu which incorrectly performs f32->u64 conversion instead
of the requested f32->u128 conversion:
sub sp, sp, #16
str s0, [sp, #12]
ldr s0, [sp, #12]
fcvtzu x8, s0
mov w0, w8
add sp, sp, #16
ret
Changing the return type to __uint128_t produces the correct conversion using a
libcall:
sub sp, sp, #32
stp x29, x30, [sp, #16]
add x29, sp, #16
stur s0, [x29, #-4]
ldur s0, [x29, #-4]
bl __fixunssfti
ldp x29, x30, [sp, #16]
add sp, sp, #32
ret
-print-after-all shows that the problem happens here:
# *** IR Dump After AArch64PreLegalizerCombiner (aarch64-prelegalizer-combiner)
***:
# Machine code for function bad: IsSSA, TracksLiveness
Frame Objects:
fi#0: size=4, align=4, at location [SP]
Function Live Ins: $s0
bb.1 (%ir-block.1):
liveins: $s0
%0:_(s32) = COPY $s0
%1:_(p0) = G_FRAME_INDEX %stack.0
G_STORE %0:_(s32), %1:_(p0) :: (store 4 into %ir.2)
%2:_(s32) = G_LOAD %1:_(p0), debug-location !22 :: (dereferenceable load 4
from %ir.2); <source>:2:25
%3:_(s128) = G_FPTOUI %2:_(s32), debug-location !23; <source>:2:12
%4:_(s32) = G_TRUNC %3:_(s128), debug-location !23; <source>:2:12
$w0 = COPY %4:_(s32), debug-location !24; <source>:2:5
RET_ReallyLR implicit $w0, debug-location !24; <source>:2:5
# End machine code for function bad.
# *** IR Dump After Legalizer (legalizer) ***:
# Machine code for function bad: IsSSA, TracksLiveness, Legalized
Frame Objects:
fi#0: size=4, align=4, at location [SP]
Function Live Ins: $s0
bb.1 (%ir-block.1):
liveins: $s0
%0:_(s32) = COPY $s0
%1:_(p0) = G_FRAME_INDEX %stack.0
G_STORE %0:_(s32), %1:_(p0) :: (store 4 into %ir.2)
%2:_(s32) = G_LOAD %1:_(p0), debug-location !22 :: (dereferenceable load 4
from %ir.2); <source>:2:25
%5:_(s64) = G_FPTOUI %2:_(s32), debug-location !23; <source>:2:12
%6:_(s64) = G_CONSTANT i64 0
%4:_(s32) = G_TRUNC %5:_(s64)
$w0 = COPY %4:_(s32), debug-location !24; <source>:2:5
RET_ReallyLR implicit $w0, debug-location !24; <source>:2:5
# End machine code for function bad</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>