[llvm] r284864 - X86: Improve BT instruction selection for 64-bit values.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 21 12:57:55 PDT 2016


Author: pcc
Date: Fri Oct 21 14:57:55 2016
New Revision: 284864

URL: http://llvm.org/viewvc/llvm-project?rev=284864&view=rev
Log:
X86: Improve BT instruction selection for 64-bit values.

If a 64-bit value is tested against a bit which is known to be in the range
[0..31) (modulo 64), we can use the 32-bit BT instruction, which has a slightly
shorter encoding.

Differential Revision: https://reviews.llvm.org/D25862

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

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=284864&r1=284863&r2=284864&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Oct 21 14:57:55 2016
@@ -15314,6 +15314,14 @@ static SDValue getBitTestCondition(SDVal
   if (Src.getValueType() == MVT::i8 || Src.getValueType() == MVT::i16)
     Src = DAG.getNode(ISD::ANY_EXTEND, dl, MVT::i32, Src);
 
+  // See if we can use the 32-bit instruction instead of the 64-bit one for a
+  // shorter encoding. Since the former takes the modulo 32 of BitNo and the
+  // latter takes the modulo 64, this is only valid if the 5th bit of BitNo is
+  // known to be zero.
+  if (Src.getValueType() == MVT::i64 &&
+      DAG.MaskedValueIsZero(BitNo, APInt(BitNo.getValueSizeInBits(), 32)))
+    Src = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Src);
+
   // If the operand types disagree, extend the shift amount to match.  Since
   // BT ignores high bits (like shifts) we can use anyextend.
   if (Src.getValueType() != BitNo.getValueType())

Modified: llvm/trunk/test/CodeGen/X86/bt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/bt.ll?rev=284864&r1=284863&r2=284864&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/bt.ll (original)
+++ llvm/trunk/test/CodeGen/X86/bt.ll Fri Oct 21 14:57:55 2016
@@ -596,3 +596,15 @@ define zeroext i1 @invert(i32 %flags, i3
   ret i1 %tobool
 }
 
+define zeroext i1 @extend(i32 %bit, i64 %bits) {
+; CHECK-LABEL: extend:
+; CHECK:       # BB#0:
+; CHECK-NEXT:  btl %edi, %esi
+entry:
+  %and = and i32 %bit, 31
+  %sh_prom = zext i32 %and to i64
+  %shl = shl i64 1, %sh_prom
+  %and1 = and i64 %shl, %bits
+  %tobool = icmp ne i64 %and1, 0
+  ret i1 %tobool
+}




More information about the llvm-commits mailing list