diff options
| author | Craig Topper <craig.topper@intel.com> | 2018-09-26 17:01:44 +0000 |
|---|---|---|
| committer | Craig Topper <craig.topper@intel.com> | 2018-09-26 17:01:44 +0000 |
| commit | fb5d9f2849a3005e1ccd9554030c5f1a30bf3c0e (patch) | |
| tree | cf7f030a2ede8265d12d1d2ded4057f05dbcc157 /clang/lib | |
| parent | 344475fce536e2f2f88d5e3b0a7bde51a2149341 (diff) | |
| download | bcm5719-llvm-fb5d9f2849a3005e1ccd9554030c5f1a30bf3c0e.tar.gz bcm5719-llvm-fb5d9f2849a3005e1ccd9554030c5f1a30bf3c0e.zip | |
[X86] For lzcnt/tzcnt intrinsics use cttz/ctlz intrinsics with zero_undef flag set to false.
Previously we used a select and the zero_undef=true intrinsic. In -O2 this pattern will get optimized to zero_undef=false. But in -O0 this optimization won't happen. This results in a compare and cmov being wrapped around a tzcnt/lzcnt instruction.
By using the zero_undef=false intrinsic directly without the select, we can improve the -O0 codegen to just an lzcnt/tzcnt instruction.
Differential Revision: https://reviews.llvm.org/D52392
llvm-svn: 343126
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 12 | ||||
| -rw-r--r-- | clang/lib/Headers/bmiintrin.h | 10 | ||||
| -rw-r--r-- | clang/lib/Headers/lzcntintrin.h | 10 |
3 files changed, 22 insertions, 10 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 23c760207b8..df71dbb4b4a 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -9164,6 +9164,18 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID, Ops[0]); return Builder.CreateExtractValue(Call, 0); } + case X86::BI__builtin_ia32_lzcnt_u16: + case X86::BI__builtin_ia32_lzcnt_u32: + case X86::BI__builtin_ia32_lzcnt_u64: { + Value *F = CGM.getIntrinsic(Intrinsic::ctlz, Ops[0]->getType()); + return Builder.CreateCall(F, {Ops[0], Builder.getInt1(false)}); + } + case X86::BI__builtin_ia32_tzcnt_u16: + case X86::BI__builtin_ia32_tzcnt_u32: + case X86::BI__builtin_ia32_tzcnt_u64: { + Value *F = CGM.getIntrinsic(Intrinsic::cttz, Ops[0]->getType()); + return Builder.CreateCall(F, {Ops[0], Builder.getInt1(false)}); + } case X86::BI__builtin_ia32_undef128: case X86::BI__builtin_ia32_undef256: case X86::BI__builtin_ia32_undef512: diff --git a/clang/lib/Headers/bmiintrin.h b/clang/lib/Headers/bmiintrin.h index d03bef442a2..56c20b78d34 100644 --- a/clang/lib/Headers/bmiintrin.h +++ b/clang/lib/Headers/bmiintrin.h @@ -62,7 +62,7 @@ static __inline__ unsigned short __RELAXED_FN_ATTRS __tzcnt_u16(unsigned short __X) { - return __X ? __builtin_ctzs(__X) : 16; + return __builtin_ia32_tzcnt_u16(__X); } /// Performs a bitwise AND of the second operand with the one's @@ -196,7 +196,7 @@ __blsr_u32(unsigned int __X) static __inline__ unsigned int __RELAXED_FN_ATTRS __tzcnt_u32(unsigned int __X) { - return __X ? __builtin_ctz(__X) : 32; + return __builtin_ia32_tzcnt_u32(__X); } /// Counts the number of trailing zero bits in the operand. @@ -212,7 +212,7 @@ __tzcnt_u32(unsigned int __X) static __inline__ int __RELAXED_FN_ATTRS _mm_tzcnt_32(unsigned int __X) { - return __X ? __builtin_ctz(__X) : 32; + return __builtin_ia32_tzcnt_u32(__X); } #ifdef __x86_64__ @@ -359,7 +359,7 @@ __blsr_u64(unsigned long long __X) static __inline__ unsigned long long __RELAXED_FN_ATTRS __tzcnt_u64(unsigned long long __X) { - return __X ? __builtin_ctzll(__X) : 64; + return __builtin_ia32_tzcnt_u64(__X); } /// Counts the number of trailing zero bits in the operand. @@ -375,7 +375,7 @@ __tzcnt_u64(unsigned long long __X) static __inline__ long long __RELAXED_FN_ATTRS _mm_tzcnt_64(unsigned long long __X) { - return __X ? __builtin_ctzll(__X) : 64; + return __builtin_ia32_tzcnt_u64(__X); } #endif /* __x86_64__ */ diff --git a/clang/lib/Headers/lzcntintrin.h b/clang/lib/Headers/lzcntintrin.h index 558f1828f0e..f2674d2a5ab 100644 --- a/clang/lib/Headers/lzcntintrin.h +++ b/clang/lib/Headers/lzcntintrin.h @@ -44,7 +44,7 @@ static __inline__ unsigned short __DEFAULT_FN_ATTRS __lzcnt16(unsigned short __X) { - return __X ? __builtin_clzs(__X) : 16; + return __builtin_ia32_lzcnt_u16(__X); } /// Counts the number of leading zero bits in the operand. @@ -61,7 +61,7 @@ __lzcnt16(unsigned short __X) static __inline__ unsigned int __DEFAULT_FN_ATTRS __lzcnt32(unsigned int __X) { - return __X ? __builtin_clz(__X) : 32; + return __builtin_ia32_lzcnt_u32(__X); } /// Counts the number of leading zero bits in the operand. @@ -78,7 +78,7 @@ __lzcnt32(unsigned int __X) static __inline__ unsigned int __DEFAULT_FN_ATTRS _lzcnt_u32(unsigned int __X) { - return __X ? __builtin_clz(__X) : 32; + return __builtin_ia32_lzcnt_u32(__X); } #ifdef __x86_64__ @@ -96,7 +96,7 @@ _lzcnt_u32(unsigned int __X) static __inline__ unsigned long long __DEFAULT_FN_ATTRS __lzcnt64(unsigned long long __X) { - return __X ? __builtin_clzll(__X) : 64; + return __builtin_ia32_lzcnt_u64(__X); } /// Counts the number of leading zero bits in the operand. @@ -113,7 +113,7 @@ __lzcnt64(unsigned long long __X) static __inline__ unsigned long long __DEFAULT_FN_ATTRS _lzcnt_u64(unsigned long long __X) { - return __X ? __builtin_clzll(__X) : 64; + return __builtin_ia32_lzcnt_u64(__X); } #endif |

