[cfe-commits] r149183 - in /cfe/trunk: include/clang/Basic/Builtins.def include/clang/Basic/BuiltinsX86.def lib/CodeGen/CGBuiltin.cpp test/CodeGen/2005-05-06-CountBuiltins.c test/CodeGen/count-builtins.c

Benjamin Kramer benny.kra at googlemail.com
Sat Jan 28 10:42:57 PST 2012


Author: d0k
Date: Sat Jan 28 12:42:57 2012
New Revision: 149183

URL: http://llvm.org/viewvc/llvm-project?rev=149183&view=rev
Log:
Make the __builtin_c[lt]zs builtins target independent.

There is really no reason to have these only available on x86. It's
just __builtin_c[tl]z for shorts.

Modernize the test while at it.

Added:
    cfe/trunk/test/CodeGen/count-builtins.c
      - copied, changed from r149182, cfe/trunk/test/CodeGen/2005-05-06-CountBuiltins.c
Removed:
    cfe/trunk/test/CodeGen/2005-05-06-CountBuiltins.c
Modified:
    cfe/trunk/include/clang/Basic/Builtins.def
    cfe/trunk/include/clang/Basic/BuiltinsX86.def
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=149183&r1=149182&r2=149183&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Sat Jan 28 12:42:57 2012
@@ -365,10 +365,12 @@
 BUILTIN(__builtin_signbitl, "iLd", "nc")
 
 // Builtins for arithmetic.
+BUILTIN(__builtin_clzs , "iUs"  , "nc")
 BUILTIN(__builtin_clz  , "iUi"  , "nc")
 BUILTIN(__builtin_clzl , "iULi" , "nc")
 BUILTIN(__builtin_clzll, "iULLi", "nc")
 // TODO: int clzimax(uintmax_t)
+BUILTIN(__builtin_ctzs , "iUs"  , "nc")
 BUILTIN(__builtin_ctz  , "iUi"  , "nc")
 BUILTIN(__builtin_ctzl , "iULi" , "nc")
 BUILTIN(__builtin_ctzll, "iULLi", "nc")

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=149183&r1=149182&r2=149183&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Sat Jan 28 12:42:57 2012
@@ -593,11 +593,7 @@
 BUILTIN(__builtin_ia32_psrlv4di, "V4LLiV4LLiV4LLi", "")
 BUILTIN(__builtin_ia32_psrlv2di, "V2LLiV2LLiV2LLi", "")
 
-// LZCNT
-BUILTIN(__builtin_clzs, "UsUs", "")
-
 // BMI
-BUILTIN(__builtin_ctzs, "UsUs", "")
 BUILTIN(__builtin_ia32_bextr_u32, "UiUiUi", "")
 BUILTIN(__builtin_ia32_bextr_u64, "ULLiULLiULLi", "")
 

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=149183&r1=149182&r2=149183&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Sat Jan 28 12:42:57 2012
@@ -229,6 +229,7 @@
 
     return RValue::get(Result);
   }
+  case Builtin::BI__builtin_ctzs:
   case Builtin::BI__builtin_ctz:
   case Builtin::BI__builtin_ctzl:
   case Builtin::BI__builtin_ctzll: {
@@ -245,6 +246,7 @@
                                      "cast");
     return RValue::get(Result);
   }
+  case Builtin::BI__builtin_clzs:
   case Builtin::BI__builtin_clz:
   case Builtin::BI__builtin_clzl:
   case Builtin::BI__builtin_clzll: {
@@ -2061,32 +2063,6 @@
 
   switch (BuiltinID) {
   default: return 0;
-  case X86::BI__builtin_clzs: {
-    Value *ArgValue = EmitScalarExpr(E->getArg(0));
-
-    llvm::Type *ArgType = ArgValue->getType();
-    Value *F = CGM.getIntrinsic(Intrinsic::ctlz, ArgType);
-
-    llvm::Type *ResultType = ConvertType(E->getType());
-    Value *Result = Builder.CreateCall2(F, ArgValue, Builder.getTrue());
-    if (Result->getType() != ResultType)
-      Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
-                                     "cast");
-    return Result;
-  }
-  case X86::BI__builtin_ctzs: {
-    Value *ArgValue = EmitScalarExpr(E->getArg(0));
-
-    llvm::Type *ArgType = ArgValue->getType();
-    Value *F = CGM.getIntrinsic(Intrinsic::cttz, ArgType);
-
-    llvm::Type *ResultType = ConvertType(E->getType());
-    Value *Result = Builder.CreateCall2(F, ArgValue, Builder.getTrue());
-    if (Result->getType() != ResultType)
-      Result = Builder.CreateIntCast(Result, ResultType, /*isSigned*/true,
-                                     "cast");
-    return Result;
-  }
   case X86::BI__builtin_ia32_pslldi128:
   case X86::BI__builtin_ia32_psllqi128:
   case X86::BI__builtin_ia32_psllwi128:

Removed: cfe/trunk/test/CodeGen/2005-05-06-CountBuiltins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/2005-05-06-CountBuiltins.c?rev=149182&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/2005-05-06-CountBuiltins.c (original)
+++ cfe/trunk/test/CodeGen/2005-05-06-CountBuiltins.c (removed)
@@ -1,17 +0,0 @@
-// RUN: %clang_cc1 %s -emit-llvm -o %t
-// RUN: not grep call*__builtin %t
-
-int G, H, I;
-void foo(int P) {
-  G = __builtin_clz(P);
-  H = __builtin_ctz(P);
-  I = __builtin_popcount(P);
-}
-
-long long g, h, i;
-void fooll(float P) {
-  g = __builtin_clzll(P);
-  g = __builtin_clzll(P);
-  h = __builtin_ctzll(P);
-  i = __builtin_popcountll(P);
-}

Copied: cfe/trunk/test/CodeGen/count-builtins.c (from r149182, cfe/trunk/test/CodeGen/2005-05-06-CountBuiltins.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/count-builtins.c?p2=cfe/trunk/test/CodeGen/count-builtins.c&p1=cfe/trunk/test/CodeGen/2005-05-06-CountBuiltins.c&r1=149182&r2=149183&rev=149183&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/2005-05-06-CountBuiltins.c (original)
+++ cfe/trunk/test/CodeGen/count-builtins.c Sat Jan 28 12:42:57 2012
@@ -1,17 +1,33 @@
-// RUN: %clang_cc1 %s -emit-llvm -o %t
-// RUN: not grep call*__builtin %t
+// RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
 
-int G, H, I;
-void foo(int P) {
-  G = __builtin_clz(P);
-  H = __builtin_ctz(P);
-  I = __builtin_popcount(P);
+int leading, trailing, pop;
+
+void test_i16(short P) {
+  leading = __builtin_clzs(P);
+  trailing = __builtin_ctzs(P);
+
+// CHECK: @test_i16
+// CHECK: call i16 @llvm.ctlz.i16
+// CHECK: call i16 @llvm.cttz.i16
+}
+
+void test_i32(int P) {
+  leading = __builtin_clz(P);
+  trailing = __builtin_ctz(P);
+  pop = __builtin_popcount(P);
+
+// CHECK: @test_i32
+// CHECK: call i32 @llvm.ctlz.i32
+// CHECK: call i32 @llvm.cttz.i32
+// CHECK: call i32 @llvm.ctpop.i32
 }
 
-long long g, h, i;
-void fooll(float P) {
-  g = __builtin_clzll(P);
-  g = __builtin_clzll(P);
-  h = __builtin_ctzll(P);
-  i = __builtin_popcountll(P);
+void test_i64(float P) {
+  leading = __builtin_clzll(P);
+  trailing = __builtin_ctzll(P);
+  pop = __builtin_popcountll(P);
+// CHECK: @test_i64
+// CHECK: call i64 @llvm.ctlz.i64
+// CHECK: call i64 @llvm.cttz.i64
+// CHECK: call i64 @llvm.ctpop.i64
 }





More information about the cfe-commits mailing list