]> granicus.if.org Git - llvm/commitdiff
[X86] Promote i8 CTPOP to i32 instead of i16 when we have the POPCNT instruction.
authorCraig Topper <craig.topper@intel.com>
Thu, 30 Nov 2017 20:15:31 +0000 (20:15 +0000)
committerCraig Topper <craig.topper@intel.com>
Thu, 30 Nov 2017 20:15:31 +0000 (20:15 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319468 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/ctpop-combine.ll
test/CodeGen/X86/popcnt.ll

index 54523d7233eda296f25d3a183d4266cc4f6a694a..45246421babd8e48ddfc3071f690244054156a3c 100644 (file)
@@ -399,7 +399,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
   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);
index 87e43a1e109864646efcba20fa2068778a494b46..955b8a144101247a68198bb1e18b8cf64d93916c 100644 (file)
@@ -54,8 +54,8 @@ define i8 @test4(i8 %x) nounwind readnone {
 ; 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)
index a4ed30e7bd9857bac204ec38bfbb0cfcf313be8b..d11f714c3e71a21a8b2f6263e51d64ac9bd4616d 100644 (file)
@@ -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