r219565 - [complex] Use the much more powerful EmitCall routine to call libcalls

Chandler Carruth chandlerc at gmail.com
Sat Oct 11 02:24:41 PDT 2014


Author: chandlerc
Date: Sat Oct 11 04:24:41 2014
New Revision: 219565

URL: http://llvm.org/viewvc/llvm-project?rev=219565&view=rev
Log:
[complex] Use the much more powerful EmitCall routine to call libcalls
for complex math.

This should fix the windows build bots that started having trouble here
and generally fix complex libcall emission on targets which use sret for
complex data types. It also makes the code a bit simpler (despite
calling into a much more complex bucket of code).

Modified:
    cfe/trunk/lib/CodeGen/CGExprComplex.cpp
    cfe/trunk/test/CodeGen/complex-math.c

Modified: cfe/trunk/lib/CodeGen/CGExprComplex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprComplex.cpp?rev=219565&r1=219564&r2=219565&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprComplex.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprComplex.cpp Sat Oct 11 04:24:41 2014
@@ -584,23 +584,7 @@ ComplexPairTy ComplexExprEmitter::EmitCo
   llvm::FunctionType *FTy = CGF.CGM.getTypes().GetFunctionType(FuncInfo);
   llvm::Constant *Func = CGF.CGM.CreateRuntimeFunction(FTy, LibCallName);
 
-  llvm::Value *ArgVals[] = {Op.LHS.first, Op.LHS.second, Op.RHS.first,
-                            Op.RHS.second};
-  llvm::Value *Result = CGF.EmitRuntimeCall(Func, ArgVals);
-
-  llvm::Value *ResR, *ResI;
-  if (Result->getType()->isVectorTy()) {
-    ResR = CGF.Builder.CreateExtractElement(Result, CGF.Builder.getInt32(0));
-    ResI = CGF.Builder.CreateExtractElement(Result, CGF.Builder.getInt32(1));
-  } else {
-    assert(Result->getType()->isAggregateType() &&
-           "Only vector and aggregate libcall returns are supported!");
-    unsigned ResRIndices[] = {0};
-    ResR = CGF.Builder.CreateExtractValue(Result, ResRIndices);
-    unsigned ResIIndices[] = {1};
-    ResI = CGF.Builder.CreateExtractValue(Result, ResIIndices);
-  }
-  return ComplexPairTy(ResR, ResI);
+  return CGF.EmitCall(FuncInfo, Func, ReturnValueSlot(), Args).getComplexVal();
 }
 
 // See C11 Annex G.5.1 for the semantics of multiplicative operators on complex

Modified: cfe/trunk/test/CodeGen/complex-math.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/complex-math.c?rev=219565&r1=219564&r2=219565&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/complex-math.c (original)
+++ cfe/trunk/test/CodeGen/complex-math.c Sat Oct 11 04:24:41 2014
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 %s -O1 -emit-llvm -triple x86_64-unknown-unknown -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 %s -O1 -emit-llvm -triple x86_64-pc-win64 -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 %s -O1 -emit-llvm -triple i686-unknown-unknown -o - | FileCheck %s --check-prefix=X86
 
 float _Complex add_float_rr(float a, float b) {
   // X86-LABEL: @add_float_rr(
@@ -87,7 +89,7 @@ float _Complex mul_float_rc(float a, flo
 float _Complex mul_float_cc(float _Complex a, float _Complex b) {
   // X86-LABEL: @mul_float_cc(
   // X86-NOT: fmul
-  // X86: call <2 x float> @__mulsc3(
+  // X86: call {{.*}} @__mulsc3(
   // X86: ret
   return a * b;
 }
@@ -110,14 +112,14 @@ float _Complex div_float_cr(float _Compl
 float _Complex div_float_rc(float a, float _Complex b) {
   // X86-LABEL: @div_float_rc(
   // X86-NOT: fdiv
-  // X86: call <2 x float> @__divsc3(
+  // X86: call {{.*}} @__divsc3(
   // X86: ret
   return a / b;
 }
 float _Complex div_float_cc(float _Complex a, float _Complex b) {
   // X86-LABEL: @div_float_cc(
   // X86-NOT: fdiv
-  // X86: call <2 x float> @__divsc3(
+  // X86: call {{.*}} @__divsc3(
   // X86: ret
   return a / b;
 }
@@ -209,7 +211,7 @@ double _Complex mul_double_rc(double a,
 double _Complex mul_double_cc(double _Complex a, double _Complex b) {
   // X86-LABEL: @mul_double_cc(
   // X86-NOT: fmul
-  // X86: call { double, double } @__muldc3(
+  // X86: call {{.*}} @__muldc3(
   // X86: ret
   return a * b;
 }
@@ -232,14 +234,14 @@ double _Complex div_double_cr(double _Co
 double _Complex div_double_rc(double a, double _Complex b) {
   // X86-LABEL: @div_double_rc(
   // X86-NOT: fdiv
-  // X86: call { double, double } @__divdc3(
+  // X86: call {{.*}} @__divdc3(
   // X86: ret
   return a / b;
 }
 double _Complex div_double_cc(double _Complex a, double _Complex b) {
   // X86-LABEL: @div_double_cc(
   // X86-NOT: fdiv
-  // X86: call { double, double } @__divdc3(
+  // X86: call {{.*}} @__divdc3(
   // X86: ret
   return a / b;
 }
@@ -331,7 +333,7 @@ long double _Complex mul_long_double_rc(
 long double _Complex mul_long_double_cc(long double _Complex a, long double _Complex b) {
   // X86-LABEL: @mul_long_double_cc(
   // X86-NOT: fmul
-  // X86: call { x86_fp80, x86_fp80 } @__mulxc3(
+  // X86: call {{.*}} @__mulxc3(
   // X86: ret
   return a * b;
 }
@@ -354,14 +356,14 @@ long double _Complex div_long_double_cr(
 long double _Complex div_long_double_rc(long double a, long double _Complex b) {
   // X86-LABEL: @div_long_double_rc(
   // X86-NOT: fdiv
-  // X86: call { x86_fp80, x86_fp80 } @__divxc3(
+  // X86: call {{.*}} @__divxc3(
   // X86: ret
   return a / b;
 }
 long double _Complex div_long_double_cc(long double _Complex a, long double _Complex b) {
   // X86-LABEL: @div_long_double_cc(
   // X86-NOT: fdiv
-  // X86: call { x86_fp80, x86_fp80 } @__divxc3(
+  // X86: call {{.*}} @__divxc3(
   // X86: ret
   return a / b;
 }





More information about the cfe-commits mailing list