[llvm] r206869 - [X86] Don't use BZHI for short masks (>=32 bits). Thanks to Ben Kramer for the

Lang Hames lhames at gmail.com
Tue Apr 22 00:40:38 PDT 2014


Author: lhames
Date: Tue Apr 22 02:40:34 2014
New Revision: 206869

URL: http://llvm.org/viewvc/llvm-project?rev=206869&view=rev
Log:
[X86] Don't use BZHI for short masks (>=32 bits). Thanks to Ben Kramer for the
review.

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/test/CodeGen/X86/bmi.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=206869&r1=206868&r2=206869&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Tue Apr 22 02:40:34 2014
@@ -18507,13 +18507,15 @@ static SDValue PerformAndCombine(SDNode
     // 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 (VT == MVT::i64 && Subtarget->hasBMI2()) {
       if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(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));
+          // Only use BZHI for immediates that are too large for an AND:
+          if (LZ > 32)
+            return DAG.getNode(X86ISD::BZHI, DL, VT, N0,
+                               DAG.getConstant(LZ, MVT::i8));
         }
       }
     }

Modified: llvm/trunk/test/CodeGen/X86/bmi.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/bmi.ll?rev=206869&r1=206868&r2=206869&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/bmi.ll (original)
+++ llvm/trunk/test/CodeGen/X86/bmi.ll Tue Apr 22 02:40:34 2014
@@ -216,22 +216,21 @@ entry:
 ; CHECK: bzhiq
 }
 
-define i32 @bzhi32_constant_mask(i32 %x) #0 {
-entry:
-  %and = and i32 %x, 1073741823
-  ret i32 %and
-; CHECK-LABEL: bzhi32_constant_mask:
-; CHECK: movb    $30, %al
-; CHECK: bzhil   %eax, %e[[ARG1:di|cx]], %eax
-}
-
 define i64 @bzhi64_constant_mask(i64 %x) #0 {
 entry:
   %and = and i64 %x, 4611686018427387903
   ret i64 %and
 ; CHECK-LABEL: bzhi64_constant_mask:
 ; CHECK: movb    $62, %al
-; CHECK: bzhiq   %rax, %r[[ARG1]], %rax
+; CHECK: bzhiq   %rax, %r[[ARG1:di|cx]], %rax
+}
+
+define i64 @bzhi64_small_constant_mask(i64 %x) #0 {
+entry:
+  %and = and i64 %x, 2147483647
+  ret i64 %and
+; CHECK-LABEL: bzhi64_small_constant_mask:
+; CHECK: andq  $2147483647, %r[[ARG1]]
 }
 
 define i32 @blsi32(i32 %x) nounwind readnone {





More information about the llvm-commits mailing list