r216341 - Implement __builtin_signbitl for PowerPC

Hal Finkel hfinkel at anl.gov
Sat Aug 23 20:47:07 PDT 2014


Author: hfinkel
Date: Sat Aug 23 22:47:06 2014
New Revision: 216341

URL: http://llvm.org/viewvc/llvm-project?rev=216341&view=rev
Log:
Implement __builtin_signbitl for PowerPC

PowerPC uses the special PPC_FP128 type for long double on Linux, which is
composed of two 64-bit doubles. The higher-order double (which contains the
overall sign) comes first, and so the __builtin_signbitl implementation
requires special handling to extract the sign bit.

Fixes PR20691.

Added:
    cfe/trunk/test/CodeGen/ppc-signbit.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=216341&r1=216340&r2=216341&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Sat Aug 23 22:47:06 2014
@@ -1347,11 +1347,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 
     Value *Arg = EmitScalarExpr(E->getArg(0));
     llvm::Type *ArgTy = Arg->getType();
-    if (ArgTy->isPPC_FP128Ty())
-      break; // FIXME: I'm not sure what the right implementation is here.
     int ArgWidth = ArgTy->getPrimitiveSizeInBits();
     llvm::Type *ArgIntTy = llvm::IntegerType::get(C, ArgWidth);
     Value *BCArg = Builder.CreateBitCast(Arg, ArgIntTy);
+    if (ArgTy->isPPC_FP128Ty()) {
+      // The higher-order double comes first, and so we need to truncate the
+      // pair to extract the overall sign. The order of the pair is the same
+      // in both little- and big-Endian modes.
+      ArgWidth >>= 1;
+      ArgIntTy = llvm::IntegerType::get(C, ArgWidth);
+      BCArg = Builder.CreateTrunc(BCArg, ArgIntTy);
+    }
     Value *ZeroCmp = llvm::Constant::getNullValue(ArgIntTy);
     Value *Result = Builder.CreateICmpSLT(BCArg, ZeroCmp);
     return RValue::get(Builder.CreateZExt(Result, ConvertType(E->getType())));

Added: cfe/trunk/test/CodeGen/ppc-signbit.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ppc-signbit.c?rev=216341&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/ppc-signbit.c (added)
+++ cfe/trunk/test/CodeGen/ppc-signbit.c Sat Aug 23 22:47:06 2014
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple powerpc64-linux-gnu | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple powerpc64le-linux-gnu | FileCheck %s
+
+int test(long double x) { return __builtin_signbitl(x); }
+
+// CHECK-LABEL: define signext i32 @test(ppc_fp128 %x)
+// CHECK: bitcast ppc_fp128 %{{.*}} to i128
+// CHECK: trunc i128 %{{.*}} to i64
+// CHECK: icmp slt i64 %{{.*}}, 0
+// CHECK: zext i1 %{{.*}} to i32
+





More information about the cfe-commits mailing list