1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py 2; RUN: llc < %s -mtriple=x86_64-unknown -mcpu=corei7 | FileCheck %s 3 4declare i8 @llvm.ctpop.i8(i8) nounwind readnone 5declare i64 @llvm.ctpop.i64(i64) nounwind readnone 6 7define i32 @test1(i64 %x) nounwind readnone { 8; CHECK-LABEL: test1: 9; CHECK: # %bb.0: 10; CHECK-NEXT: leaq -1(%rdi), %rcx 11; CHECK-NEXT: xorl %eax, %eax 12; CHECK-NEXT: testq %rcx, %rdi 13; CHECK-NEXT: setne %al 14; CHECK-NEXT: retq 15 %count = tail call i64 @llvm.ctpop.i64(i64 %x) 16 %cast = trunc i64 %count to i32 17 %cmp = icmp ugt i32 %cast, 1 18 %conv = zext i1 %cmp to i32 19 ret i32 %conv 20} 21 22 23define i32 @test2(i64 %x) nounwind readnone { 24; CHECK-LABEL: test2: 25; CHECK: # %bb.0: 26; CHECK-NEXT: leaq -1(%rdi), %rcx 27; CHECK-NEXT: xorl %eax, %eax 28; CHECK-NEXT: testq %rcx, %rdi 29; CHECK-NEXT: sete %al 30; CHECK-NEXT: retq 31 %count = tail call i64 @llvm.ctpop.i64(i64 %x) 32 %cmp = icmp ult i64 %count, 2 33 %conv = zext i1 %cmp to i32 34 ret i32 %conv 35} 36 37define i32 @test3(i64 %x) nounwind readnone { 38; CHECK-LABEL: test3: 39; CHECK: # %bb.0: 40; CHECK-NEXT: popcntq %rdi, %rcx 41; CHECK-NEXT: andb $63, %cl 42; CHECK-NEXT: xorl %eax, %eax 43; CHECK-NEXT: cmpb $2, %cl 44; CHECK-NEXT: setb %al 45; CHECK-NEXT: retq 46 %count = tail call i64 @llvm.ctpop.i64(i64 %x) 47 %cast = trunc i64 %count to i6 ; Too small for 0-64 48 %cmp = icmp ult i6 %cast, 2 49 %conv = zext i1 %cmp to i32 50 ret i32 %conv 51} 52 53define i8 @test4(i8 %x) nounwind readnone { 54; CHECK-LABEL: test4: 55; CHECK: # %bb.0: 56; CHECK-NEXT: andl $127, %edi 57; CHECK-NEXT: popcntl %edi, %eax 58; CHECK-NEXT: # kill: def $al killed $al killed $eax 59; CHECK-NEXT: retq 60 %x2 = and i8 %x, 127 61 %count = tail call i8 @llvm.ctpop.i8(i8 %x2) 62 %and = and i8 %count, 7 63 ret i8 %and 64} 65