[llvm] 2949bae - [X86] Add test case to demonstrate a Log2_32_Ceil that can just be Log2_32 in SimplifySetCC ctpop combine.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 14 10:24:18 PDT 2020


Author: Craig Topper
Date: 2020-10-14T10:22:51-07:00
New Revision: 2949baec3cc84cc6640f70d1f8aa3153c953b26a

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

LOG: [X86] Add test case to demonstrate a Log2_32_Ceil that can just be Log2_32 in SimplifySetCC ctpop combine.

This combine can look through (trunc (ctpop X)). When doing this
it tries to make sure the trunc doesn't lose any information
from the ctpop. It does this by checking that the truncated type
has more bits that Log2_32_Ceil of the ctpop type. The Ceil is
unnecessary and pessimizes non-power of 2 types.

For example, ctpop of i256 requires 9 bits to represent the max
value of 256. But ctpop of i255 only requires 8 bits to represent
the max result of 255. Log2_32_Ceil of 256 and 255 both return 8
while Log2_32 returns 8 for 256 and 7 for 255.

Added: 
    

Modified: 
    llvm/test/CodeGen/X86/ctpop-combine.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/CodeGen/X86/ctpop-combine.ll b/llvm/test/CodeGen/X86/ctpop-combine.ll
index e60935cc8732..c3bea4923530 100644
--- a/llvm/test/CodeGen/X86/ctpop-combine.ll
+++ b/llvm/test/CodeGen/X86/ctpop-combine.ll
@@ -160,3 +160,101 @@ define i32 @ctpop_ne_one(i64 %x) nounwind readnone {
   %conv = zext i1 %cmp to i32
   ret i32 %conv
 }
+
+define i1 @ctpop_trunc_non_power2(i255 %x) {
+; POPCOUNT-LABEL: ctpop_trunc_non_power2:
+; POPCOUNT:       # %bb.0:
+; POPCOUNT-NEXT:    movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
+; POPCOUNT-NEXT:    andq %rcx, %rax
+; POPCOUNT-NEXT:    popcntq %rsi, %rcx
+; POPCOUNT-NEXT:    popcntq %rdi, %rsi
+; POPCOUNT-NEXT:    addl %ecx, %esi
+; POPCOUNT-NEXT:    popcntq %rax, %rax
+; POPCOUNT-NEXT:    popcntq %rdx, %rcx
+; POPCOUNT-NEXT:    addl %eax, %ecx
+; POPCOUNT-NEXT:    addl %esi, %ecx
+; POPCOUNT-NEXT:    cmpb $1, %cl
+; POPCOUNT-NEXT:    sete %al
+; POPCOUNT-NEXT:    retq
+;
+; NO-POPCOUNT-LABEL: ctpop_trunc_non_power2:
+; NO-POPCOUNT:       # %bb.0:
+; NO-POPCOUNT-NEXT:    movabsq $9223372036854775807, %rax # imm = 0x7FFFFFFFFFFFFFFF
+; NO-POPCOUNT-NEXT:    andq %rcx, %rax
+; NO-POPCOUNT-NEXT:    movq %rsi, %rcx
+; NO-POPCOUNT-NEXT:    shrq %rcx
+; NO-POPCOUNT-NEXT:    movabsq $6148914691236517205, %r8 # imm = 0x5555555555555555
+; NO-POPCOUNT-NEXT:    andq %r8, %rcx
+; NO-POPCOUNT-NEXT:    subq %rcx, %rsi
+; NO-POPCOUNT-NEXT:    movabsq $3689348814741910323, %r11 # imm = 0x3333333333333333
+; NO-POPCOUNT-NEXT:    movq %rsi, %rcx
+; NO-POPCOUNT-NEXT:    andq %r11, %rcx
+; NO-POPCOUNT-NEXT:    shrq $2, %rsi
+; NO-POPCOUNT-NEXT:    andq %r11, %rsi
+; NO-POPCOUNT-NEXT:    addq %rcx, %rsi
+; NO-POPCOUNT-NEXT:    movq %rsi, %rcx
+; NO-POPCOUNT-NEXT:    shrq $4, %rcx
+; NO-POPCOUNT-NEXT:    addq %rsi, %rcx
+; NO-POPCOUNT-NEXT:    movabsq $1085102592571150095, %r9 # imm = 0xF0F0F0F0F0F0F0F
+; NO-POPCOUNT-NEXT:    andq %r9, %rcx
+; NO-POPCOUNT-NEXT:    movabsq $72340172838076673, %r10 # imm = 0x101010101010101
+; NO-POPCOUNT-NEXT:    imulq %r10, %rcx
+; NO-POPCOUNT-NEXT:    shrq $56, %rcx
+; NO-POPCOUNT-NEXT:    movq %rdi, %rsi
+; NO-POPCOUNT-NEXT:    shrq %rsi
+; NO-POPCOUNT-NEXT:    andq %r8, %rsi
+; NO-POPCOUNT-NEXT:    subq %rsi, %rdi
+; NO-POPCOUNT-NEXT:    movq %rdi, %rsi
+; NO-POPCOUNT-NEXT:    andq %r11, %rsi
+; NO-POPCOUNT-NEXT:    shrq $2, %rdi
+; NO-POPCOUNT-NEXT:    andq %r11, %rdi
+; NO-POPCOUNT-NEXT:    addq %rsi, %rdi
+; NO-POPCOUNT-NEXT:    movq %rdi, %rsi
+; NO-POPCOUNT-NEXT:    shrq $4, %rsi
+; NO-POPCOUNT-NEXT:    addq %rdi, %rsi
+; NO-POPCOUNT-NEXT:    andq %r9, %rsi
+; NO-POPCOUNT-NEXT:    imulq %r10, %rsi
+; NO-POPCOUNT-NEXT:    shrq $56, %rsi
+; NO-POPCOUNT-NEXT:    addl %ecx, %esi
+; NO-POPCOUNT-NEXT:    movq %rax, %rcx
+; NO-POPCOUNT-NEXT:    shrq %rcx
+; NO-POPCOUNT-NEXT:    movabsq $1537228672809129301, %rdi # imm = 0x1555555555555555
+; NO-POPCOUNT-NEXT:    andq %rcx, %rdi
+; NO-POPCOUNT-NEXT:    subq %rdi, %rax
+; NO-POPCOUNT-NEXT:    movq %rax, %rcx
+; NO-POPCOUNT-NEXT:    andq %r11, %rcx
+; NO-POPCOUNT-NEXT:    shrq $2, %rax
+; NO-POPCOUNT-NEXT:    andq %r11, %rax
+; NO-POPCOUNT-NEXT:    addq %rcx, %rax
+; NO-POPCOUNT-NEXT:    movq %rax, %rcx
+; NO-POPCOUNT-NEXT:    shrq $4, %rcx
+; NO-POPCOUNT-NEXT:    addq %rax, %rcx
+; NO-POPCOUNT-NEXT:    andq %r9, %rcx
+; NO-POPCOUNT-NEXT:    imulq %r10, %rcx
+; NO-POPCOUNT-NEXT:    shrq $56, %rcx
+; NO-POPCOUNT-NEXT:    movq %rdx, %rax
+; NO-POPCOUNT-NEXT:    shrq %rax
+; NO-POPCOUNT-NEXT:    andq %r8, %rax
+; NO-POPCOUNT-NEXT:    subq %rax, %rdx
+; NO-POPCOUNT-NEXT:    movq %rdx, %rax
+; NO-POPCOUNT-NEXT:    andq %r11, %rax
+; NO-POPCOUNT-NEXT:    shrq $2, %rdx
+; NO-POPCOUNT-NEXT:    andq %r11, %rdx
+; NO-POPCOUNT-NEXT:    addq %rax, %rdx
+; NO-POPCOUNT-NEXT:    movq %rdx, %rax
+; NO-POPCOUNT-NEXT:    shrq $4, %rax
+; NO-POPCOUNT-NEXT:    addq %rdx, %rax
+; NO-POPCOUNT-NEXT:    andq %r9, %rax
+; NO-POPCOUNT-NEXT:    imulq %r10, %rax
+; NO-POPCOUNT-NEXT:    shrq $56, %rax
+; NO-POPCOUNT-NEXT:    addl %ecx, %eax
+; NO-POPCOUNT-NEXT:    addl %esi, %eax
+; NO-POPCOUNT-NEXT:    cmpb $1, %al
+; NO-POPCOUNT-NEXT:    sete %al
+; NO-POPCOUNT-NEXT:    retq
+  %a = call i255 @llvm.ctpop.i255(i255 %x)
+  %b = trunc i255 %a to i8 ; largest value from ctpop is 255, fits in 8 bits.
+  %c = icmp eq i8 %b, 1
+  ret i1 %c
+}
+declare i255 @llvm.ctpop.i255(i255)


        


More information about the llvm-commits mailing list