[PATCH] D17760: [mips] Fix an issue with long double when function roundl is defined

Zlatko Buljan via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 1 05:19:26 PST 2016


zbuljan created this revision.
zbuljan added reviewers: dsanders, zoran.jovanovic, hvarga.
zbuljan added subscribers: petarj, llvm-commits.
Herald added a reviewer: vkalintiris.
Herald added a subscriber: dsanders.

Patch adds `roundl` to a list of library calls in isF128SoftLibCall method (MipsCCState.cpp).
Test file `roundl-call.ll` is also added to LLVM regression tests.

Problem description:
There was a problem in LLVM backend that is triggered with next C code:

```
#include <math.h>

int main() {
  long double x, y;
  y = roundl(x);
  return 0;
}
```

With clang we generate IR code using `-emit-llvm` option (roundl-call.ll):

```
clang -static -O0 --target=mips64-img-linux-gnu -EL -mcpu=mips64r6 -mabi=64 -mhard-float -no-integrated-as --gcc-toolchain=/home/rtrk/mips-toolchain/mips-img-linux-gnu/2015.01-7 -S -emit-llvm roundl-test.c
```

Then we generate assembler code from `roundl-call.ll` with llc:

```
llc -march=mips64el -mcpu=mips64r3 -target-abi=n64 -O2 < roundl-call.ll
```

We can see that generated assembler code is using the wrong convention for roundl call.

Soft-float registers `V0_64` and `V1_64` are used for storing result instead of hard-float registers:

```
sd  $3, 8($fp)
sd  $2, 0($fp)
```

After the patch is applied and we generate assembler code again from the same .ll file.
Now we can see that FPU registers `D0_64` and `D2_64` are used as it is expected for hard-float:

```
sdc1  $f2, 8($fp)
sdc1  $f0, 0($fp)
```

*This bug is also reported on bugzilla (https://dmz-portal.mips.com/bugz/show_bug.cgi?id=2303).

http://reviews.llvm.org/D17760

Files:
  lib/Target/Mips/MipsCCState.cpp
  test/CodeGen/Mips/roundl-call.ll

Index: test/CodeGen/Mips/roundl-call.ll
===================================================================
--- /dev/null
+++ test/CodeGen/Mips/roundl-call.ll
@@ -0,0 +1,26 @@
+; RUN: llc -march=mips64el -mcpu=mips64   -target-abi=n64 < %s | FileCheck %s
+; RUN: llc -march=mips64el -mcpu=mips64r2 -target-abi=n64 < %s | FileCheck %s
+; RUN: llc -march=mips64el -mcpu=mips64r3 -target-abi=n64 < %s | FileCheck %s
+; RUN: llc -march=mips64el -mcpu=mips64r6 -target-abi=n64 < %s | FileCheck %s
+
+define i32 @main() #0 {
+entry:
+; CHECK-LABEL: main:
+; CHECK:      ld        $25, %call16(roundl)($gp)
+; CHECK:      sdc1      $f2, 8($fp)
+; CHECK:      sdc1      $f0, 0($fp)
+  %retval = alloca i32, align 4
+  %x = alloca fp128, align 16
+  %y = alloca fp128, align 16
+  store i32 0, i32* %retval, align 4
+  %0 = load fp128, fp128* %x, align 16
+  %call = call fp128 @roundl(fp128 %0) #2
+  store fp128 %call, fp128* %y, align 16
+  ret i32 0
+}
+
+declare fp128 @roundl(fp128) #1
+
+attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="mips64r6" "target-features"="+mips64r6" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="mips64r6" "target-features"="+mips64r6" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #2 = { nounwind readnone }
Index: lib/Target/Mips/MipsCCState.cpp
===================================================================
--- lib/Target/Mips/MipsCCState.cpp
+++ lib/Target/Mips/MipsCCState.cpp
@@ -26,8 +26,8 @@
       "ceill",         "copysignl",    "cosl",          "exp2l",
       "expl",          "floorl",       "fmal",          "fmodl",
       "log10l",        "log2l",        "logl",          "nearbyintl",
-      "powl",          "rintl",        "sinl",          "sqrtl",
-      "truncl"};
+      "powl",          "rintl",        "roundl",        "sinl",
+      "sqrtl",         "truncl"};
 
   // Check that LibCalls is sorted alphabetically.
   auto Comp = [](const char *S1, const char *S2) { return strcmp(S1, S2) < 0; };


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17760.49476.patch
Type: text/x-patch
Size: 2437 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160301/1ab93ba0/attachment-0001.bin>


More information about the llvm-commits mailing list