[llvm] r319468 - [X86] Promote i8 CTPOP to i32 instead of i16 when we have the POPCNT instruction.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 12:15:31 PST 2017


Author: ctopper
Date: Thu Nov 30 12:15:31 2017
New Revision: 319468

URL: http://llvm.org/viewvc/llvm-project?rev=319468&view=rev
Log:
[X86] Promote i8 CTPOP to i32 instead of i16 when we have the POPCNT instruction.

The 32-bit version is shorter to encode and the zext we emit for the promotion is likely going to be a 32-bit zero extend anyway.

Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
    llvm/trunk/test/CodeGen/X86/ctpop-combine.ll
    llvm/trunk/test/CodeGen/X86/popcnt.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=319468&r1=319467&r2=319468&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Thu Nov 30 12:15:31 2017
@@ -399,7 +399,7 @@ X86TargetLowering::X86TargetLowering(con
   setTruncStoreAction(MVT::f80, MVT::f16, Expand);
 
   if (Subtarget.hasPOPCNT()) {
-    setOperationAction(ISD::CTPOP          , MVT::i8   , Promote);
+    setOperationPromotedToType(ISD::CTPOP, MVT::i8, MVT::i32);
   } else {
     setOperationAction(ISD::CTPOP          , MVT::i8   , Expand);
     setOperationAction(ISD::CTPOP          , MVT::i16  , Expand);

Modified: llvm/trunk/test/CodeGen/X86/ctpop-combine.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/ctpop-combine.ll?rev=319468&r1=319467&r2=319468&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/ctpop-combine.ll (original)
+++ llvm/trunk/test/CodeGen/X86/ctpop-combine.ll Thu Nov 30 12:15:31 2017
@@ -54,8 +54,8 @@ define i8 @test4(i8 %x) nounwind readnon
 ; CHECK-LABEL: test4:
 ; CHECK:       # BB#0:
 ; CHECK-NEXT:    andl $127, %edi
-; CHECK-NEXT:    popcntw %di, %ax
-; CHECK-NEXT:    # kill: %al<def> %al<kill> %ax<kill>
+; CHECK-NEXT:    popcntl %edi, %eax
+; CHECK-NEXT:    # kill: %al<def> %al<kill> %eax<kill>
 ; CHECK-NEXT:    retq
   %x2 = and i8 %x, 127
   %count = tail call i8 @llvm.ctpop.i8(i8 %x2)

Modified: llvm/trunk/test/CodeGen/X86/popcnt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/popcnt.ll?rev=319468&r1=319467&r2=319468&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/popcnt.ll (original)
+++ llvm/trunk/test/CodeGen/X86/popcnt.ll Thu Nov 30 12:15:31 2017
@@ -43,15 +43,15 @@ define i8 @cnt8(i8 %x) nounwind readnone
 ; X32-POPCNT-LABEL: cnt8:
 ; X32-POPCNT:       # BB#0:
 ; X32-POPCNT-NEXT:    movzbl {{[0-9]+}}(%esp), %eax
-; X32-POPCNT-NEXT:    popcntw %ax, %ax
-; X32-POPCNT-NEXT:    # kill: %al<def> %al<kill> %ax<kill>
+; X32-POPCNT-NEXT:    popcntl %eax, %eax
+; X32-POPCNT-NEXT:    # kill: %al<def> %al<kill> %eax<kill>
 ; X32-POPCNT-NEXT:    retl
 ;
 ; X64-POPCNT-LABEL: cnt8:
 ; X64-POPCNT:       # BB#0:
 ; X64-POPCNT-NEXT:    movzbl %dil, %eax
-; X64-POPCNT-NEXT:    popcntw %ax, %ax
-; X64-POPCNT-NEXT:    # kill: %al<def> %al<kill> %ax<kill>
+; X64-POPCNT-NEXT:    popcntl %eax, %eax
+; X64-POPCNT-NEXT:    # kill: %al<def> %al<kill> %eax<kill>
 ; X64-POPCNT-NEXT:    retq
   %cnt = tail call i8 @llvm.ctpop.i8(i8 %x)
   ret i8 %cnt




More information about the llvm-commits mailing list