From: Craig Topper Date: Thu, 30 Nov 2017 20:15:31 +0000 (+0000) Subject: [X86] Promote i8 CTPOP to i32 instead of i16 when we have the POPCNT instruction. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d6aaba398813dfb5255dab9c6909187a058d90e6;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319468 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 54523d7233e..45246421bab 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -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); diff --git a/test/CodeGen/X86/ctpop-combine.ll b/test/CodeGen/X86/ctpop-combine.ll index 87e43a1e109..955b8a14410 100644 --- a/test/CodeGen/X86/ctpop-combine.ll +++ b/test/CodeGen/X86/ctpop-combine.ll @@ -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 %al %ax +; CHECK-NEXT: popcntl %edi, %eax +; CHECK-NEXT: # kill: %al %al %eax ; CHECK-NEXT: retq %x2 = and i8 %x, 127 %count = tail call i8 @llvm.ctpop.i8(i8 %x2) diff --git a/test/CodeGen/X86/popcnt.ll b/test/CodeGen/X86/popcnt.ll index a4ed30e7bd9..d11f714c3e7 100644 --- a/test/CodeGen/X86/popcnt.ll +++ b/test/CodeGen/X86/popcnt.ll @@ -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 %al %ax +; X32-POPCNT-NEXT: popcntl %eax, %eax +; X32-POPCNT-NEXT: # kill: %al %al %eax ; 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 %al %ax +; X64-POPCNT-NEXT: popcntl %eax, %eax +; X64-POPCNT-NEXT: # kill: %al %al %eax ; X64-POPCNT-NEXT: retq %cnt = tail call i8 @llvm.ctpop.i8(i8 %x) ret i8 %cnt