r272564 - [immintrin] Reimplement _bit_scan_{forward,reverse}

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 13 10:26:17 PDT 2016


Author: majnemer
Date: Mon Jun 13 12:26:16 2016
New Revision: 272564

URL: http://llvm.org/viewvc/llvm-project?rev=272564&view=rev
Log:
[immintrin] Reimplement _bit_scan_{forward,reverse}

There is no need to use a target-specific intrinsic to implement
_bit_scan_forward or _bit_scan_reverse, reimplementing them using
generic intrinsics makes it more likely that the middle end will
understand what's going on.

Modified:
    cfe/trunk/lib/Headers/immintrin.h
    cfe/trunk/test/CodeGen/bitscan-builtins.c

Modified: cfe/trunk/lib/Headers/immintrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/immintrin.h?rev=272564&r1=272563&r2=272564&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/immintrin.h (original)
+++ cfe/trunk/lib/Headers/immintrin.h Mon Jun 13 12:26:16 2016
@@ -172,13 +172,13 @@ _rdrand32_step(unsigned int *__p)
 /* __bit_scan_forward */
 static __inline__ int __attribute__((__always_inline__, __nodebug__))
 _bit_scan_forward(int __A) {
- return __builtin_ia32_bit_scan_forward(__A);
+  return __builtin_ctz(__A);
 }
 
 /* __bit_scan_reverse */
 static __inline__ int __attribute__((__always_inline__, __nodebug__))
 _bit_scan_reverse(int __A) {
- return __builtin_ia32_bit_scan_reverse(__A);
+  return 31 - __builtin_clz(__A);
 }
 
 #ifdef __x86_64__

Modified: cfe/trunk/test/CodeGen/bitscan-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/bitscan-builtins.c?rev=272564&r1=272563&r2=272564&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/bitscan-builtins.c (original)
+++ cfe/trunk/test/CodeGen/bitscan-builtins.c Mon Jun 13 12:26:16 2016
@@ -7,11 +7,13 @@
 int test_bit_scan_forward(int a) {
   return _bit_scan_forward(a);
 // CHECK: @test_bit_scan_forward
-// CHECK: call i32 @llvm.x86.bit.scan.forward
+// CHECK: %[[call:.*]] = call i32 @llvm.cttz.i32(
+// CHECK: ret i32 %[[call]]
 }
 
 int test_bit_scan_reverse(int a) {
   return _bit_scan_reverse(a);
-// CHECK: @test_bit_scan_reverse
-// CHECK: call i32 @llvm.x86.bit.scan.reverse
+// CHECK:  %[[call:.*]] = call i32 @llvm.ctlz.i32(
+// CHECK:  %[[sub:.*]] = sub nsw i32 31, %2
+// CHECK: ret i32 %[[sub]]
 }




More information about the cfe-commits mailing list