forked from OSchip/llvm-project
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. llvm-svn: 216341
This commit is contained in:
parent
c2b7f7a6ab
commit
6208251923
|
@ -1347,11 +1347,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
|
|||
|
||||
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())));
|
||||
|
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue