[llvm-bugs] [Bug 49710] New: LLVM 12 regression: AArch64 backend generates incorrect code for f32 to i128 conversion

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 24 04:47:20 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=49710

            Bug ID: 49710
           Summary: LLVM 12 regression: AArch64 backend generates
                    incorrect code for f32 to i128 conversion
           Product: libraries
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Backend: AArch64
          Assignee: unassignedbugs at nondot.org
          Reporter: amanieu at gmail.com
                CC: arnaud.degrandmaison at arm.com,
                    llvm-bugs at lists.llvm.org, smithp352 at googlemail.com,
                    Ties.Stuij at arm.com

This bug was found while running the tests for
https://github.com/rust-lang/compiler-builtins 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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210324/dd96d191/attachment.html>


More information about the llvm-bugs mailing list