From f69bb5e43c1427d23800e4e678a7c2f2088f0c88 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 21 Apr 2014 08:18:53 +0000 Subject: [X86] ISEL (and X, ) to BZHI when BMI2 is available. Generating BZHI in the variable mask case, i.e. (and X, (sub (shl 1, N), 1)), was already supported, but we were missing the constant-mask case. This patch fixes that. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206738 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ISelLowering.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib') diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 306fb7e199..d867414a98 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -18503,6 +18503,20 @@ static SDValue PerformAndCombine(SDNode *N, SelectionDAG &DAG, } } // BEXTR + // Check for BZHI with contiguous mask: (and X, 0x0..0f..f) + // This should be checked after BEXTR - when X is a shift, a BEXTR is + // preferrable. + if (Subtarget->hasBMI2()) { + if (ConstantSDNode *C = dyn_cast(N1)) { + uint64_t Mask = C->getZExtValue(); + if (isMask_64(Mask)) { + unsigned LZ = CountTrailingOnes_64(Mask); + return DAG.getNode(X86ISD::BZHI, DL, VT, N0, + DAG.getConstant(LZ, MVT::i8)); + } + } + } + return SDValue(); } -- cgit v1.2.3