[llvm] f89d59a - [X86] Add parity test cases for PR46954.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 1 23:00:29 PDT 2020


Author: Craig Topper
Date: 2020-08-01T22:52:33-07:00
New Revision: f89d59a0853f90c54dea60500831d02901623223

URL: https://github.com/llvm/llvm-project/commit/f89d59a0853f90c54dea60500831d02901623223
DIFF: https://github.com/llvm/llvm-project/commit/f89d59a0853f90c54dea60500831d02901623223.diff

LOG: [X86] Add parity test cases for PR46954.

This adds tests cases where the parity idiom of (and (ctpop X, 1))
has a truncate in the middle.

Added: 
    

Modified: 
    llvm/test/CodeGen/X86/parity.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/CodeGen/X86/parity.ll b/llvm/test/CodeGen/X86/parity.ll
index 9ad04db8c280..404d7a68a6e7 100644
--- a/llvm/test/CodeGen/X86/parity.ll
+++ b/llvm/test/CodeGen/X86/parity.ll
@@ -92,5 +92,152 @@ define i64 @parity_64(i64 %x) {
   ret i64 %2
 }
 
+define i32 @parity_64_trunc(i64 %x) {
+; X86-NOPOPCNT-LABEL: parity_64_trunc:
+; X86-NOPOPCNT:       # %bb.0:
+; X86-NOPOPCNT-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; X86-NOPOPCNT-NEXT:    movl {{[0-9]+}}(%esp), %ecx
+; X86-NOPOPCNT-NEXT:    movl %ecx, %edx
+; X86-NOPOPCNT-NEXT:    shrl %edx
+; X86-NOPOPCNT-NEXT:    andl $1431655765, %edx # imm = 0x55555555
+; X86-NOPOPCNT-NEXT:    subl %edx, %ecx
+; X86-NOPOPCNT-NEXT:    movl %ecx, %edx
+; X86-NOPOPCNT-NEXT:    andl $858993459, %edx # imm = 0x33333333
+; X86-NOPOPCNT-NEXT:    shrl $2, %ecx
+; X86-NOPOPCNT-NEXT:    andl $858993459, %ecx # imm = 0x33333333
+; X86-NOPOPCNT-NEXT:    addl %edx, %ecx
+; X86-NOPOPCNT-NEXT:    movl %ecx, %edx
+; X86-NOPOPCNT-NEXT:    shrl $4, %edx
+; X86-NOPOPCNT-NEXT:    addl %ecx, %edx
+; X86-NOPOPCNT-NEXT:    andl $17764111, %edx # imm = 0x10F0F0F
+; X86-NOPOPCNT-NEXT:    imull $16843009, %edx, %ecx # imm = 0x1010101
+; X86-NOPOPCNT-NEXT:    shrl $24, %ecx
+; X86-NOPOPCNT-NEXT:    movl %eax, %edx
+; X86-NOPOPCNT-NEXT:    shrl %edx
+; X86-NOPOPCNT-NEXT:    andl $1431655765, %edx # imm = 0x55555555
+; X86-NOPOPCNT-NEXT:    subl %edx, %eax
+; X86-NOPOPCNT-NEXT:    movl %eax, %edx
+; X86-NOPOPCNT-NEXT:    andl $858993459, %edx # imm = 0x33333333
+; X86-NOPOPCNT-NEXT:    shrl $2, %eax
+; X86-NOPOPCNT-NEXT:    andl $858993459, %eax # imm = 0x33333333
+; X86-NOPOPCNT-NEXT:    addl %edx, %eax
+; X86-NOPOPCNT-NEXT:    movl %eax, %edx
+; X86-NOPOPCNT-NEXT:    shrl $4, %edx
+; X86-NOPOPCNT-NEXT:    addl %eax, %edx
+; X86-NOPOPCNT-NEXT:    andl $17764111, %edx # imm = 0x10F0F0F
+; X86-NOPOPCNT-NEXT:    imull $16843009, %edx, %eax # imm = 0x1010101
+; X86-NOPOPCNT-NEXT:    shrl $24, %eax
+; X86-NOPOPCNT-NEXT:    addl %ecx, %eax
+; X86-NOPOPCNT-NEXT:    andl $1, %eax
+; X86-NOPOPCNT-NEXT:    retl
+;
+; X64-NOPOPCNT-LABEL: parity_64_trunc:
+; X64-NOPOPCNT:       # %bb.0:
+; X64-NOPOPCNT-NEXT:    movq %rdi, %rax
+; X64-NOPOPCNT-NEXT:    shrq %rax
+; X64-NOPOPCNT-NEXT:    movabsq $6148914691236517205, %rcx # imm = 0x5555555555555555
+; X64-NOPOPCNT-NEXT:    andq %rax, %rcx
+; X64-NOPOPCNT-NEXT:    subq %rcx, %rdi
+; X64-NOPOPCNT-NEXT:    movabsq $3689348814741910323, %rax # imm = 0x3333333333333333
+; X64-NOPOPCNT-NEXT:    movq %rdi, %rcx
+; X64-NOPOPCNT-NEXT:    andq %rax, %rcx
+; X64-NOPOPCNT-NEXT:    shrq $2, %rdi
+; X64-NOPOPCNT-NEXT:    andq %rax, %rdi
+; X64-NOPOPCNT-NEXT:    addq %rcx, %rdi
+; X64-NOPOPCNT-NEXT:    movq %rdi, %rax
+; X64-NOPOPCNT-NEXT:    shrq $4, %rax
+; X64-NOPOPCNT-NEXT:    addq %rdi, %rax
+; X64-NOPOPCNT-NEXT:    movabsq $76296276040158991, %rcx # imm = 0x10F0F0F0F0F0F0F
+; X64-NOPOPCNT-NEXT:    andq %rax, %rcx
+; X64-NOPOPCNT-NEXT:    movabsq $72340172838076673, %rax # imm = 0x101010101010101
+; X64-NOPOPCNT-NEXT:    imulq %rcx, %rax
+; X64-NOPOPCNT-NEXT:    shrq $56, %rax
+; X64-NOPOPCNT-NEXT:    andl $1, %eax
+; X64-NOPOPCNT-NEXT:    # kill: def $eax killed $eax killed $rax
+; X64-NOPOPCNT-NEXT:    retq
+;
+; X86-POPCNT-LABEL: parity_64_trunc:
+; X86-POPCNT:       # %bb.0:
+; X86-POPCNT-NEXT:    popcntl {{[0-9]+}}(%esp), %ecx
+; X86-POPCNT-NEXT:    popcntl {{[0-9]+}}(%esp), %eax
+; X86-POPCNT-NEXT:    addl %ecx, %eax
+; X86-POPCNT-NEXT:    andl $1, %eax
+; X86-POPCNT-NEXT:    retl
+;
+; X64-POPCNT-LABEL: parity_64_trunc:
+; X64-POPCNT:       # %bb.0:
+; X64-POPCNT-NEXT:    popcntq %rdi, %rax
+; X64-POPCNT-NEXT:    andl $1, %eax
+; X64-POPCNT-NEXT:    # kill: def $eax killed $eax killed $rax
+; X64-POPCNT-NEXT:    retq
+  %1 = tail call i64 @llvm.ctpop.i64(i64 %x)
+  %2 = trunc i64 %1 to i32
+  %3 = and i32 %2, 1
+  ret i32 %3
+}
+
+define i8 @parity_32_trunc(i32 %x) {
+; X86-NOPOPCNT-LABEL: parity_32_trunc:
+; X86-NOPOPCNT:       # %bb.0:
+; X86-NOPOPCNT-NEXT:    movl {{[0-9]+}}(%esp), %eax
+; X86-NOPOPCNT-NEXT:    movl %eax, %ecx
+; X86-NOPOPCNT-NEXT:    shrl %ecx
+; X86-NOPOPCNT-NEXT:    andl $1431655765, %ecx # imm = 0x55555555
+; X86-NOPOPCNT-NEXT:    subl %ecx, %eax
+; X86-NOPOPCNT-NEXT:    movl %eax, %ecx
+; X86-NOPOPCNT-NEXT:    andl $858993459, %ecx # imm = 0x33333333
+; X86-NOPOPCNT-NEXT:    shrl $2, %eax
+; X86-NOPOPCNT-NEXT:    andl $858993459, %eax # imm = 0x33333333
+; X86-NOPOPCNT-NEXT:    addl %ecx, %eax
+; X86-NOPOPCNT-NEXT:    movl %eax, %ecx
+; X86-NOPOPCNT-NEXT:    shrl $4, %ecx
+; X86-NOPOPCNT-NEXT:    addl %eax, %ecx
+; X86-NOPOPCNT-NEXT:    andl $17764111, %ecx # imm = 0x10F0F0F
+; X86-NOPOPCNT-NEXT:    imull $16843009, %ecx, %eax # imm = 0x1010101
+; X86-NOPOPCNT-NEXT:    shrl $24, %eax
+; X86-NOPOPCNT-NEXT:    andb $1, %al
+; X86-NOPOPCNT-NEXT:    # kill: def $al killed $al killed $eax
+; X86-NOPOPCNT-NEXT:    retl
+;
+; X64-NOPOPCNT-LABEL: parity_32_trunc:
+; X64-NOPOPCNT:       # %bb.0:
+; X64-NOPOPCNT-NEXT:    movl %edi, %eax
+; X64-NOPOPCNT-NEXT:    shrl %eax
+; X64-NOPOPCNT-NEXT:    andl $1431655765, %eax # imm = 0x55555555
+; X64-NOPOPCNT-NEXT:    subl %eax, %edi
+; X64-NOPOPCNT-NEXT:    movl %edi, %eax
+; X64-NOPOPCNT-NEXT:    andl $858993459, %eax # imm = 0x33333333
+; X64-NOPOPCNT-NEXT:    shrl $2, %edi
+; X64-NOPOPCNT-NEXT:    andl $858993459, %edi # imm = 0x33333333
+; X64-NOPOPCNT-NEXT:    addl %eax, %edi
+; X64-NOPOPCNT-NEXT:    movl %edi, %eax
+; X64-NOPOPCNT-NEXT:    shrl $4, %eax
+; X64-NOPOPCNT-NEXT:    addl %edi, %eax
+; X64-NOPOPCNT-NEXT:    andl $17764111, %eax # imm = 0x10F0F0F
+; X64-NOPOPCNT-NEXT:    imull $16843009, %eax, %eax # imm = 0x1010101
+; X64-NOPOPCNT-NEXT:    shrl $24, %eax
+; X64-NOPOPCNT-NEXT:    andb $1, %al
+; X64-NOPOPCNT-NEXT:    # kill: def $al killed $al killed $eax
+; X64-NOPOPCNT-NEXT:    retq
+;
+; X86-POPCNT-LABEL: parity_32_trunc:
+; X86-POPCNT:       # %bb.0:
+; X86-POPCNT-NEXT:    popcntl {{[0-9]+}}(%esp), %eax
+; X86-POPCNT-NEXT:    andb $1, %al
+; X86-POPCNT-NEXT:    # kill: def $al killed $al killed $eax
+; X86-POPCNT-NEXT:    retl
+;
+; X64-POPCNT-LABEL: parity_32_trunc:
+; X64-POPCNT:       # %bb.0:
+; X64-POPCNT-NEXT:    popcntl %edi, %eax
+; X64-POPCNT-NEXT:    andb $1, %al
+; X64-POPCNT-NEXT:    # kill: def $al killed $al killed $eax
+; X64-POPCNT-NEXT:    retq
+  %1 = tail call i32 @llvm.ctpop.i32(i32 %x)
+  %2 = trunc i32 %1 to i8
+  %3 = and i8 %2, 1
+  ret i8 %3
+}
+
 declare i32 @llvm.ctpop.i32(i32 %x)
 declare i64 @llvm.ctpop.i64(i64 %x)


        


More information about the llvm-commits mailing list