[cfe-commits] r161891 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp test/CodeGen/complex-builtints.c
Fariborz Jahanian
fjahanian at apple.com
Tue Aug 14 13:09:28 PDT 2012
Author: fjahanian
Date: Tue Aug 14 15:09:28 2012
New Revision: 161891
URL: http://llvm.org/viewvc/llvm-project?rev=161891&view=rev
Log:
irgen: inline code for several of complex builtin
calls. // rdar://8315199
Added:
cfe/trunk/test/CodeGen/complex-builtints.c
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=161891&r1=161890&r2=161891&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Aug 14 15:09:28 2012
@@ -229,6 +229,35 @@
return RValue::get(Result);
}
+
+ case Builtin::BI__builtin_conj:
+ case Builtin::BI__builtin_conjf:
+ case Builtin::BI__builtin_conjl: {
+ ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0));
+ Value *Real = ComplexVal.first;
+ Value *Imag = ComplexVal.second;
+ Value *Zero =
+ Imag->getType()->isFPOrFPVectorTy()
+ ? llvm::ConstantFP::getZeroValueForNegation(Imag->getType())
+ : llvm::Constant::getNullValue(Imag->getType());
+
+ Imag = Builder.CreateFSub(Zero, Imag, "sub");
+ return RValue::getComplex(std::make_pair(Real, Imag));
+ }
+ case Builtin::BI__builtin_creal:
+ case Builtin::BI__builtin_crealf:
+ case Builtin::BI__builtin_creall: {
+ ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0));
+ return RValue::get(ComplexVal.first);
+ }
+
+ case Builtin::BI__builtin_cimag:
+ case Builtin::BI__builtin_cimagf:
+ case Builtin::BI__builtin_cimagl: {
+ ComplexPairTy ComplexVal = EmitComplexExpr(E->getArg(0));
+ return RValue::get(ComplexVal.second);
+ }
+
case Builtin::BI__builtin_ctzs:
case Builtin::BI__builtin_ctz:
case Builtin::BI__builtin_ctzl:
Added: cfe/trunk/test/CodeGen/complex-builtints.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/complex-builtints.c?rev=161891&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/complex-builtints.c (added)
+++ cfe/trunk/test/CodeGen/complex-builtints.c Tue Aug 14 15:09:28 2012
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 %s -O1 -emit-llvm -o - | FileCheck %s
+// rdar://8315199
+
+/* Test for builtin conj, creal, cimag. */
+/* Origin: Joseph Myers <jsm28 at cam.ac.uk> */
+
+extern float _Complex conjf (float _Complex);
+extern double _Complex conj (double _Complex);
+extern long double _Complex conjl (long double _Complex);
+
+extern float crealf (float _Complex);
+extern double creal (double _Complex);
+extern long double creall (long double _Complex);
+
+extern float cimagf (float _Complex);
+extern double cimag (double _Complex);
+extern long double cimagl (long double _Complex);
+
+extern void abort (void);
+extern void link_error (void);
+
+int
+main ()
+{
+ /* For each type, test both runtime and compile time (constant folding)
+ optimization. */
+ volatile float _Complex fc = 1.0F + 2.0iF;
+ volatile double _Complex dc = 1.0 + 2.0i;
+ volatile long double _Complex ldc = 1.0L + 2.0iL;
+ /* Test floats. */
+ if (__builtin_conjf (fc) != 1.0F - 2.0iF)
+ abort ();
+ if (__builtin_conjf (1.0F + 2.0iF) != 1.0F - 2.0iF)
+ link_error ();
+ if (__builtin_crealf (fc) != 1.0F)
+ abort ();
+ if (__builtin_crealf (1.0F + 2.0iF) != 1.0F)
+ link_error ();
+ if (__builtin_cimagf (fc) != 2.0F)
+ abort ();
+ if (__builtin_cimagf (1.0F + 2.0iF) != 2.0F)
+ link_error ();
+ /* Test doubles. */
+ if (__builtin_conj (dc) != 1.0 - 2.0i)
+ abort ();
+ if (__builtin_conj (1.0 + 2.0i) != 1.0 - 2.0i)
+ link_error ();
+ if (__builtin_creal (dc) != 1.0)
+ abort ();
+ if (__builtin_creal (1.0 + 2.0i) != 1.0)
+ link_error ();
+ if (__builtin_cimag (dc) != 2.0)
+ abort ();
+ if (__builtin_cimag (1.0 + 2.0i) != 2.0)
+ link_error ();
+ /* Test long doubles. */
+ if (__builtin_conjl (ldc) != 1.0L - 2.0iL)
+ abort ();
+ if (__builtin_conjl (1.0L + 2.0iL) != 1.0L - 2.0iL)
+ link_error ();
+ if (__builtin_creall (ldc) != 1.0L)
+ abort ();
+ if (__builtin_creall (1.0L + 2.0iL) != 1.0L)
+ link_error ();
+ if (__builtin_cimagl (ldc) != 2.0L)
+ abort ();
+ if (__builtin_cimagl (1.0L + 2.0iL) != 2.0L)
+ link_error ();
+}
+
+// CHECK-NOT: link_error
More information about the cfe-commits
mailing list