[cfe-commits] r51595 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtin-count-zeros.c
Eli Friedman
eli.friedman at gmail.com
Tue May 27 08:32:46 PDT 2008
Author: efriedma
Date: Tue May 27 10:32:46 2008
New Revision: 51595
URL: http://llvm.org/viewvc/llvm-project?rev=51595&view=rev
Log:
Implementation of __builtin_ctlz.
Added:
cfe/trunk/test/CodeGen/builtin-count-zeros.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=51595&r1=51594&r2=51595&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue May 27 10:32:46 2008
@@ -192,6 +192,20 @@
Result = Builder.CreateIntCast(Result, ResultType, "cast");
return RValue::get(Result);
}
+ case Builtin::BI__builtin_clz:
+ case Builtin::BI__builtin_clzl:
+ case Builtin::BI__builtin_clzll: {
+ Value *ArgValue = EmitScalarExpr(E->getArg(0));
+
+ const llvm::Type *ArgType = ArgValue->getType();
+ Value *F = CGM.getIntrinsic(Intrinsic::ctlz, &ArgType, 1);
+
+ const llvm::Type *ResultType = ConvertType(E->getType());
+ Value *Result = Builder.CreateCall(F, ArgValue, "tmp");
+ if (Result->getType() != ResultType)
+ Result = Builder.CreateIntCast(Result, ResultType, "cast");
+ return RValue::get(Result);
+ }
case Builtin::BI__builtin_expect:
return RValue::get(EmitScalarExpr(E->getArg(0)));
case Builtin::BI__builtin_bswap32:
Added: cfe/trunk/test/CodeGen/builtin-count-zeros.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-count-zeros.c?rev=51595&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/builtin-count-zeros.c (added)
+++ cfe/trunk/test/CodeGen/builtin-count-zeros.c Tue May 27 10:32:46 2008
@@ -0,0 +1,4 @@
+// RUN: clang -emit-llvm %s -o - | grep 'cttz' | count 2
+// RUN: clang -emit-llvm %s -o - | grep 'ctlz' | count 2
+
+int a(int a) {return __builtin_ctz(a) + __builtin_clz(a);}
More information about the cfe-commits
mailing list