Skip to content

Commit

Permalink
Adding back-end support to two bit scanning intrinsics
Browse files Browse the repository at this point in the history
Adding LLVM back-end support to two intrinsics dealing with bit scan: _bit_scan_forward and _bit_scan_reverse.
Their functionality is as described in Intel intrinsics guide:
https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_bit_scan_forward&expand=371,370
https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_bit_scan_reverse&expand=371,370

Commit on behalf of Omer Paparo Bivas


Differential Revision: http://reviews.llvm.org/D19915

llvm-svn: 271386
  • Loading branch information
michaelz-eng committed Jun 1, 2016
1 parent 140b1fb commit 6a89495
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
10 changes: 10 additions & 0 deletions llvm/include/llvm/IR/IntrinsicsX86.td
Original file line number Diff line number Diff line change
Expand Up @@ -8442,3 +8442,13 @@ let TargetPrefix = "x86" in {
: GCCBuiltin<"__builtin_ia32_mwaitx">,
Intrinsic<[], [ llvm_i32_ty, llvm_i32_ty, llvm_i32_ty ], []>;
}

//===----------------------------------------------------------------------===//
// Bit Scan intrinsics
let TargetPrefix = "x86" in {
def int_x86_bit_scan_forward_32 : GCCBuiltin<"__builtin_ia32_bit_scan_forward">,
Intrinsic<[llvm_i32_ty], [llvm_i32_ty], [IntrNoMem]>;

def int_x86_bit_scan_reverse_32 : GCCBuiltin<"__builtin_ia32_bit_scan_reverse">,
Intrinsic<[llvm_i32_ty], [llvm_i32_ty], [IntrNoMem]>;
}
2 changes: 2 additions & 0 deletions llvm/lib/Target/X86/X86IntrinsicsInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,8 @@ static const IntrinsicData IntrinsicsWithoutChain[] = {
X86ISD::SCALAR_FP_TO_UINT_RND, 0),
X86_INTRINSIC_DATA(avx512_vcvtss2usi64, INTR_TYPE_2OP,
X86ISD::SCALAR_FP_TO_UINT_RND, 0),
X86_INTRINSIC_DATA(bit_scan_forward_32, INTR_TYPE_1OP, X86ISD::BSF, 0),
X86_INTRINSIC_DATA(bit_scan_reverse_32, INTR_TYPE_1OP, X86ISD::BSR, 0),
X86_INTRINSIC_DATA(fma_vfmadd_pd, INTR_TYPE_3OP, X86ISD::FMADD, 0),
X86_INTRINSIC_DATA(fma_vfmadd_pd_256, INTR_TYPE_3OP, X86ISD::FMADD, 0),
X86_INTRINSIC_DATA(fma_vfmadd_ps, INTR_TYPE_3OP, X86ISD::FMADD, 0),
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/CodeGen/X86/bitscan.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mcpu=corei7 | FileCheck %s --check-prefix=ALL --check-prefix=64-BIT
; RUN: llc < %s -mtriple=i386-unknown-unknown -mcpu=corei7 | FileCheck %s --check-prefix=ALL --check-prefix=32-BIT
declare i32 @llvm.x86.bit.scan.forward.32(i32 %val)
declare i32 @llvm.x86.bit.scan.reverse.32(i32 %val)

define i32 @test_bsf(i32 %val) {
%call = call i32 @llvm.x86.bit.scan.forward.32(i32 %val)
ret i32 %call

; ALL-LABEL: test_bsf:
; 64-BIT: bsfl %edi, %eax
; 32-BIT: bsfl 4(%esp), %eax
}

define i32 @test_bsr(i32 %val) {
%call = call i32 @llvm.x86.bit.scan.reverse.32(i32 %val)
ret i32 %call

; ALL-LABEL: test_bsr:
; 64-BIT: bsrl %edi, %eax
; 32-BIT: bsrl 4(%esp), %eax
}

0 comments on commit 6a89495

Please sign in to comment.