2012/1/16 Eli Friedman <[email protected]>

> On Mon, Jan 16, 2012 at 8:24 AM, Ruben Van Boxem
> <[email protected]> wrote:
> > Hi,
> >
> > Is there a specific reason why Clang does not have
> > __builtin_labs
> > __builtin_llabs
>
> No, probably just nobody got around to adding them.
>

I had an attempt at adding the __builtin's mentioned above. I tested with
current trunk attached patch. It just adds the two builtin names and puts
it in the same codegen part as regular abs. I hope this is correct, I had a
quick check of llabs with -2^61 and printf using "%lld".

Thanks,

Ruben

PS: If patch is OK, please commit, I don't have commit rights.
Index: include/clang/Basic/Builtins.def
===================================================================
--- include/clang/Basic/Builtins.def    (revision 148240)
+++ include/clang/Basic/Builtins.def    (working copy)
@@ -108,6 +108,8 @@
 BUILTIN(__builtin_inf  , "d"   , "nc")
 BUILTIN(__builtin_inff , "f"   , "nc")
 BUILTIN(__builtin_infl , "Ld"  , "nc")
+BUILTIN(__builtin_labs , "LiLi"  , "Fnc")
+BUILTIN(__builtin_llabs, "LLiLLi", "Fnc")
 BUILTIN(__builtin_ldexp , "ddi"  , "Fnc")
 BUILTIN(__builtin_ldexpf, "ffi"  , "Fnc")
 BUILTIN(__builtin_ldexpl, "LdLdi", "Fnc")
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp   (revision 148240)
+++ lib/CodeGen/CGBuiltin.cpp   (working copy)
@@ -214,7 +214,9 @@
     return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy),
                                            DstPtr, SrcPtr));
   }
-  case Builtin::BI__builtin_abs: {
+  case Builtin::BI__builtin_abs: 
+  case Builtin::BI__builtin_labs:
+  case Builtin::BI__builtin_llabs: {
     Value *ArgValue = EmitScalarExpr(E->getArg(0));
 
     Value *NegOp = Builder.CreateNeg(ArgValue, "neg");
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to