[PATCH] D72028: [CodeGen] Emit conj/conjf/confjl libcalls as fneg instructions if possible.

Craig Topper via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 30 23:21:00 PST 2019


craig.topper created this revision.
craig.topper added reviewers: spatel, efriedma, rjmccall.
Herald added a project: clang.

We already recognize the __builtin versions of these, might as well
recognize the libcall version.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72028

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/complex-libcalls-2.c
  clang/test/CodeGen/complex-libcalls.c


Index: clang/test/CodeGen/complex-libcalls.c
===================================================================
--- clang/test/CodeGen/complex-libcalls.c
+++ clang/test/CodeGen/complex-libcalls.c
@@ -112,12 +112,10 @@
 
   conj(f);       conjf(f);      conjl(f);
 
-// NO__ERRNO: declare { double, double } @conj(double, double) [[READNONE:#[0-9]+]]
-// NO__ERRNO: declare <2 x float> @conjf(<2 x float>) [[READNONE]]
-// NO__ERRNO: declare { x86_fp80, x86_fp80 } @conjl({ x86_fp80, x86_fp80 }* byval({ x86_fp80, x86_fp80 }) align 16) [[NOT_READNONE]]
-// HAS_ERRNO: declare { double, double } @conj(double, double) [[READNONE:#[0-9]+]]
-// HAS_ERRNO: declare <2 x float> @conjf(<2 x float>) [[READNONE]]
-// HAS_ERRNO: declare { x86_fp80, x86_fp80 } @conjl({ x86_fp80, x86_fp80 }* byval({ x86_fp80, x86_fp80 }) align 16) [[NOT_READNONE]]
+// NO__ERRNO-NOT: .conj
+// NO__ERRNO-NOT: @conj
+// HAS_ERRNO-NOT: .conj
+// HAS_ERRNO-NOT: @conj
 
   clog(f);       clogf(f);      clogl(f);
 
@@ -133,7 +131,7 @@
 // NO__ERRNO: declare { double, double } @cproj(double, double) [[READNONE]]
 // NO__ERRNO: declare <2 x float> @cprojf(<2 x float>) [[READNONE]]
 // NO__ERRNO: declare { x86_fp80, x86_fp80 } @cprojl({ x86_fp80, x86_fp80 }* byval({ x86_fp80, x86_fp80 }) align 16) [[NOT_READNONE]]
-// HAS_ERRNO: declare { double, double } @cproj(double, double) [[READNONE]]
+// HAS_ERRNO: declare { double, double } @cproj(double, double) [[READNONE:#[0-9]+]]
 // HAS_ERRNO: declare <2 x float> @cprojf(<2 x float>) [[READNONE]]
 // HAS_ERRNO: declare { x86_fp80, x86_fp80 } @cprojl({ x86_fp80, x86_fp80 }* byval({ x86_fp80, x86_fp80 }) align 16) [[NOT_READNONE]]
 
Index: clang/test/CodeGen/complex-libcalls-2.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/complex-libcalls-2.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -S -o - -emit-llvm              %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -w -S -o - -emit-llvm -fmath-errno %s | FileCheck %s
+
+float _Complex test_conjf(float _Complex x) {
+// CHECK-LABEL: @test_conjf(
+// CHECK: fneg float %x.imag
+  return conjf(x);
+}
+
+double _Complex test_conj(double _Complex x) {
+// CHECK-LABEL: @test_conj(
+// CHECK: fneg double %x.imag
+  return conj(x);
+}
+
+long double _Complex test_conjl(long double _Complex x) {
+// CHECK-LABEL: @test_conjl(
+// CHECK: fneg x86_fp80 %x.imag
+  return conjl(x);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===================================================================
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1938,7 +1938,10 @@
   }
   case Builtin::BI__builtin_conj:
   case Builtin::BI__builtin_conjf:
-  case Builtin::BI__builtin_conjl: {
+  case Builtin::BI__builtin_conjl:
+  case Builtin::BIconj:
+  case Builtin::BIconjf:
+  case Builtin::BIconjl: {
     ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0));
     Value *Real = ComplexVal.first;
     Value *Imag = ComplexVal.second;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72028.235676.patch
Type: text/x-patch
Size: 3037 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191231/86a9d8bd/attachment.bin>


More information about the cfe-commits mailing list