1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 3
2 ; RUN: llc < %s -mtriple=x86_64-unknown | FileCheck %s
4 ; When optimize for size, the constant $858993459 is moved into a register,
5 ; and use that register in following two andl instructions.
7 define i32 @cnt32_optsize(i32 %x) nounwind readnone optsize {
8 ; CHECK-LABEL: cnt32_optsize:
10 ; CHECK-NEXT: movl %edi, %eax
11 ; CHECK-NEXT: shrl %eax
12 ; CHECK-NEXT: andl $1431655765, %eax # imm = 0x55555555
13 ; CHECK-NEXT: subl %eax, %edi
14 ; CHECK-NEXT: movl $858993459, %eax # imm = 0x33333333
15 ; CHECK-NEXT: movl %edi, %ecx
16 ; CHECK-NEXT: andl %eax, %ecx
17 ; CHECK-NEXT: shrl $2, %edi
18 ; CHECK-NEXT: andl %eax, %edi
19 ; CHECK-NEXT: addl %ecx, %edi
20 ; CHECK-NEXT: movl %edi, %eax
21 ; CHECK-NEXT: shrl $4, %eax
22 ; CHECK-NEXT: addl %edi, %eax
23 ; CHECK-NEXT: andl $252645135, %eax # imm = 0xF0F0F0F
24 ; CHECK-NEXT: imull $16843009, %eax, %eax # imm = 0x1010101
25 ; CHECK-NEXT: shrl $24, %eax
27 %cnt = tail call i32 @llvm.ctpop.i32(i32 %x)
31 ; When optimize for speed, the constant $858993459 can be directly folded into
32 ; two andl instructions.
34 define i32 @cnt32_optspeed(i32 %x) nounwind readnone {
35 ; CHECK-LABEL: cnt32_optspeed:
37 ; CHECK-NEXT: movl %edi, %eax
38 ; CHECK-NEXT: shrl %eax
39 ; CHECK-NEXT: andl $1431655765, %eax # imm = 0x55555555
40 ; CHECK-NEXT: subl %eax, %edi
41 ; CHECK-NEXT: movl %edi, %eax
42 ; CHECK-NEXT: andl $858993459, %eax # imm = 0x33333333
43 ; CHECK-NEXT: shrl $2, %edi
44 ; CHECK-NEXT: andl $858993459, %edi # imm = 0x33333333
45 ; CHECK-NEXT: addl %eax, %edi
46 ; CHECK-NEXT: movl %edi, %eax
47 ; CHECK-NEXT: shrl $4, %eax
48 ; CHECK-NEXT: addl %edi, %eax
49 ; CHECK-NEXT: andl $252645135, %eax # imm = 0xF0F0F0F
50 ; CHECK-NEXT: imull $16843009, %eax, %eax # imm = 0x1010101
51 ; CHECK-NEXT: shrl $24, %eax
53 %cnt = tail call i32 @llvm.ctpop.i32(i32 %x)
57 declare i32 @llvm.ctpop.i32(i32) nounwind readnone