[dragonegg PATCH] Implement __builtin_signbit

Peter Collingbourne peter at pcc.me.uk
Thu Jun 27 11:00:58 PDT 2013


On Thu, Jun 27, 2013 at 06:21:13PM +0200, Duncan Sands wrote:
> 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.

Changed.

>> +      int ArgWidth = ArgTy->getPrimitiveSizeInBits();
>
> Personally I preferred unsigned to int in this context.

Changed.

>> +      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.

Result is an i1, so zero extension should cause us to return 0 or 1
(consistent with GCC) regardless of the signedness of the return type.

Thanks,
-- 
Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Implement-__builtin_signbit.patch
Type: text/x-diff
Size: 3106 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130627/aefea658/attachment.patch>


More information about the llvm-commits mailing list