[PATCH] D101662: [X86] Promote 16-bit CTTZ_ZERO_UNDEF to 32-bit variant

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 30 13:43:46 PDT 2021


xbolva00 created this revision.
xbolva00 added reviewers: craig.topper, RKSimon.
Herald added subscribers: pengfei, hiraditya.
xbolva00 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Related to PR50172.

Protects us against regressions after we will start doing cttz(zext(x)) -> zext(cttz(x)) transformation in the middle-end.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101662

Files:
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/clz.ll


Index: llvm/test/CodeGen/X86/clz.ll
===================================================================
--- llvm/test/CodeGen/X86/clz.ll
+++ llvm/test/CodeGen/X86/clz.ll
@@ -56,12 +56,14 @@
 ;
 ; X86-CLZ-LABEL: cttz_i16:
 ; X86-CLZ:       # %bb.0:
-; X86-CLZ-NEXT:    tzcntw {{[0-9]+}}(%esp), %ax
+; X86-CLZ-NEXT:    tzcntl {{[0-9]+}}(%esp), %eax
+; X86-CLZ-NEXT:    # kill: def $ax killed $ax killed $eax
 ; X86-CLZ-NEXT:    retl
 ;
 ; X64-CLZ-LABEL: cttz_i16:
 ; X64-CLZ:       # %bb.0:
-; X64-CLZ-NEXT:    tzcntw %di, %ax
+; X64-CLZ-NEXT:    tzcntl %edi, %eax
+; X64-CLZ-NEXT:    # kill: def $ax killed $ax killed $eax
 ; X64-CLZ-NEXT:    retq
   %tmp = call i16 @llvm.cttz.i16( i16 %x, i1 true )
   ret i16 %tmp
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -364,6 +364,12 @@
   // encoding.
   setOperationPromotedToType(ISD::CTTZ           , MVT::i8   , MVT::i32);
   setOperationPromotedToType(ISD::CTTZ_ZERO_UNDEF, MVT::i8   , MVT::i32);
+
+  // Promote the i16 zero undef variant and force them on up to i32 when tzcnt
+  // is enabled.
+  if (Subtarget.hasBMI())
+    setOperationPromotedToType(ISD::CTTZ_ZERO_UNDEF, MVT::i16, MVT::i32);
+
   if (!Subtarget.hasBMI()) {
     setOperationAction(ISD::CTTZ           , MVT::i16  , Custom);
     setOperationAction(ISD::CTTZ           , MVT::i32  , Custom);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101662.342028.patch
Type: text/x-patch
Size: 1474 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210430/feb59ce8/attachment.bin>


More information about the llvm-commits mailing list