[dragonegg PATCH] Implement __builtin_signbit

Duncan Sands baldrick at free.fr
Thu Jun 27 09:21:13 PDT 2013


Hi Peter,

On 26/06/13 01:55, Peter Collingbourne wrote:
> Hi,
>
> This patch implements __builtin_signbit*.
>
> OK to commit?
>
> Thanks,
>

> @@ -5405,6 +5410,18 @@ bool TreeToLLVM::EmitBuiltinCall(gimple stmt, tree fndecl,
>        }
>      }
>
> +    Value *TreeToLLVM::EmitBuiltinSIGNBIT(gimple stmt) {
> +      Value *Arg = EmitRegister(gimple_call_arg(stmt, 0));
> +      llvm::Type *ArgTy = Arg->getType();

No need to for llvm:: qualifier.

> +      int ArgWidth = ArgTy->getPrimitiveSizeInBits();

Personally I preferred unsigned to int in this context.

> +      llvm::Type *ArgIntTy = llvm::IntegerType::get(Context, ArgWidth);
> +      Value *BCArg = Builder.CreateBitCast(Arg, ArgIntTy);
> +      Value *ZeroCmp = llvm::Constant::getNullValue(ArgIntTy);
> +      Value *Result = Builder.CreateICmpSLT(BCArg, ZeroCmp);
> +      return Builder.CreateZExt(Result,
> +                                ConvertType(gimple_call_return_type(stmt)));

I think the extension type should be based on the signedness of the return type,
rather than assuming it is an unsigned type.

Ciao, Duncan.

> +    }
> +





More information about the llvm-commits mailing list