brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.9 KiB · 73152e9 Raw
181 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc < %s -mtriple=x86_64-unknown -mattr=+popcnt | FileCheck %s -check-prefixes=CHECK,POPCOUNT3; RUN: llc < %s -mtriple=x86_64-unknown -mattr=-popcnt | FileCheck %s -check-prefixes=CHECK,NO-POPCOUNT4 5declare i8 @llvm.ctpop.i8(i8) nounwind readnone6declare i64 @llvm.ctpop.i64(i64) nounwind readnone7 8define i32 @test1(i64 %x) nounwind readnone {9; CHECK-LABEL: test1:10; CHECK:       # %bb.0:11; CHECK-NEXT:    leaq -1(%rdi), %rcx12; CHECK-NEXT:    xorl %eax, %eax13; CHECK-NEXT:    testq %rcx, %rdi14; CHECK-NEXT:    setne %al15; CHECK-NEXT:    retq16  %count = tail call i64 @llvm.ctpop.i64(i64 %x)17  %cast = trunc i64 %count to i3218  %cmp = icmp ugt i32 %cast, 119  %conv = zext i1 %cmp to i3220  ret i32 %conv21}22 23 24define i32 @test2(i64 %x) nounwind readnone {25; CHECK-LABEL: test2:26; CHECK:       # %bb.0:27; CHECK-NEXT:    leaq -1(%rdi), %rcx28; CHECK-NEXT:    xorl %eax, %eax29; CHECK-NEXT:    testq %rcx, %rdi30; CHECK-NEXT:    sete %al31; CHECK-NEXT:    retq32  %count = tail call i64 @llvm.ctpop.i64(i64 %x)33  %cmp = icmp ult i64 %count, 234  %conv = zext i1 %cmp to i3235  ret i32 %conv36}37 38define i32 @test3(i64 %x) nounwind readnone {39; POPCOUNT-LABEL: test3:40; POPCOUNT:       # %bb.0:41; POPCOUNT-NEXT:    popcntq %rdi, %rcx42; POPCOUNT-NEXT:    andb $63, %cl43; POPCOUNT-NEXT:    xorl %eax, %eax44; POPCOUNT-NEXT:    cmpb $2, %cl45; POPCOUNT-NEXT:    setb %al46; POPCOUNT-NEXT:    retq47;48; NO-POPCOUNT-LABEL: test3:49; NO-POPCOUNT:       # %bb.0:50; NO-POPCOUNT-NEXT:    movq %rdi, %rax51; NO-POPCOUNT-NEXT:    shrq %rax52; NO-POPCOUNT-NEXT:    movabsq $6148914691236517205, %rcx # imm = 0x555555555555555553; NO-POPCOUNT-NEXT:    andq %rax, %rcx54; NO-POPCOUNT-NEXT:    subq %rcx, %rdi55; NO-POPCOUNT-NEXT:    movabsq $3689348814741910323, %rax # imm = 0x333333333333333356; NO-POPCOUNT-NEXT:    movq %rdi, %rcx57; NO-POPCOUNT-NEXT:    andq %rax, %rcx58; NO-POPCOUNT-NEXT:    shrq $2, %rdi59; NO-POPCOUNT-NEXT:    andq %rax, %rdi60; NO-POPCOUNT-NEXT:    addq %rcx, %rdi61; NO-POPCOUNT-NEXT:    movq %rdi, %rax62; NO-POPCOUNT-NEXT:    shrq $4, %rax63; NO-POPCOUNT-NEXT:    addq %rdi, %rax64; NO-POPCOUNT-NEXT:    movabsq $1085102592571150095, %rcx # imm = 0xF0F0F0F0F0F0F0F65; NO-POPCOUNT-NEXT:    andq %rax, %rcx66; NO-POPCOUNT-NEXT:    movabsq $72340172838076673, %rdx # imm = 0x10101010101010167; NO-POPCOUNT-NEXT:    imulq %rcx, %rdx68; NO-POPCOUNT-NEXT:    shrq $56, %rdx69; NO-POPCOUNT-NEXT:    andb $63, %dl70; NO-POPCOUNT-NEXT:    xorl %eax, %eax71; NO-POPCOUNT-NEXT:    cmpb $2, %dl72; NO-POPCOUNT-NEXT:    setb %al73; NO-POPCOUNT-NEXT:    retq74  %count = tail call i64 @llvm.ctpop.i64(i64 %x)75  %cast = trunc i64 %count to i6 ; Too small for 0-6476  %cmp = icmp ult i6 %cast, 277  %conv = zext i1 %cmp to i3278  ret i32 %conv79}80 81define i8 @test4(i8 %x) nounwind readnone {82; POPCOUNT-LABEL: test4:83; POPCOUNT:       # %bb.0:84; POPCOUNT-NEXT:    andl $127, %edi85; POPCOUNT-NEXT:    popcntl %edi, %eax86; POPCOUNT-NEXT:    # kill: def $al killed $al killed $eax87; POPCOUNT-NEXT:    retq88;89; NO-POPCOUNT-LABEL: test4:90; NO-POPCOUNT:       # %bb.0:91; NO-POPCOUNT-NEXT:    andl $127, %edi92; NO-POPCOUNT-NEXT:    imull $134480385, %edi, %eax # imm = 0x804020193; NO-POPCOUNT-NEXT:    shrl $3, %eax94; NO-POPCOUNT-NEXT:    andl $286331153, %eax # imm = 0x1111111195; NO-POPCOUNT-NEXT:    imull $286331153, %eax, %eax # imm = 0x1111111196; NO-POPCOUNT-NEXT:    shrl $28, %eax97; NO-POPCOUNT-NEXT:    # kill: def $al killed $al killed $eax98; NO-POPCOUNT-NEXT:    retq99  %x2 = and i8 %x, 127100  %count = tail call i8 @llvm.ctpop.i8(i8 %x2)101  %and = and i8 %count, 7102  ret i8 %and103}104 105define i32 @ctpop_eq_one(i64 %x) nounwind readnone {106; POPCOUNT-LABEL: ctpop_eq_one:107; POPCOUNT:       # %bb.0:108; POPCOUNT-NEXT:    popcntq %rdi, %rcx109; POPCOUNT-NEXT:    xorl %eax, %eax110; POPCOUNT-NEXT:    cmpl $1, %ecx111; POPCOUNT-NEXT:    sete %al112; POPCOUNT-NEXT:    retq113;114; NO-POPCOUNT-LABEL: ctpop_eq_one:115; NO-POPCOUNT:       # %bb.0:116; NO-POPCOUNT-NEXT:    leaq -1(%rdi), %rcx117; NO-POPCOUNT-NEXT:    xorq %rcx, %rdi118; NO-POPCOUNT-NEXT:    xorl %eax, %eax119; NO-POPCOUNT-NEXT:    cmpq %rcx, %rdi120; NO-POPCOUNT-NEXT:    seta %al121; NO-POPCOUNT-NEXT:    retq122  %count = tail call i64 @llvm.ctpop.i64(i64 %x)123  %cmp = icmp eq i64 %count, 1124  %conv = zext i1 %cmp to i32125  ret i32 %conv126}127 128define i32 @ctpop_ne_one(i64 %x) nounwind readnone {129; POPCOUNT-LABEL: ctpop_ne_one:130; POPCOUNT:       # %bb.0:131; POPCOUNT-NEXT:    popcntq %rdi, %rcx132; POPCOUNT-NEXT:    xorl %eax, %eax133; POPCOUNT-NEXT:    cmpl $1, %ecx134; POPCOUNT-NEXT:    setne %al135; POPCOUNT-NEXT:    retq136;137; NO-POPCOUNT-LABEL: ctpop_ne_one:138; NO-POPCOUNT:       # %bb.0:139; NO-POPCOUNT-NEXT:    leaq -1(%rdi), %rcx140; NO-POPCOUNT-NEXT:    xorq %rcx, %rdi141; NO-POPCOUNT-NEXT:    xorl %eax, %eax142; NO-POPCOUNT-NEXT:    cmpq %rcx, %rdi143; NO-POPCOUNT-NEXT:    setbe %al144; NO-POPCOUNT-NEXT:    retq145  %count = tail call i64 @llvm.ctpop.i64(i64 %x)146  %cmp = icmp ne i64 %count, 1147  %conv = zext i1 %cmp to i32148  ret i32 %conv149}150 151define i1 @ctpop_trunc_non_power2(i255 %x) nounwind {152; CHECK-LABEL: ctpop_trunc_non_power2:153; CHECK:       # %bb.0:154; CHECK-NEXT:    movq %rdi, %rax155; CHECK-NEXT:    addq $-1, %rax156; CHECK-NEXT:    movq %rsi, %r8157; CHECK-NEXT:    adcq $-1, %r8158; CHECK-NEXT:    movq %rdx, %r9159; CHECK-NEXT:    adcq $-1, %r9160; CHECK-NEXT:    movabsq $9223372036854775807, %r10 # imm = 0x7FFFFFFFFFFFFFFF161; CHECK-NEXT:    movq %rcx, %r11162; CHECK-NEXT:    adcq %r10, %r11163; CHECK-NEXT:    xorq %r11, %rcx164; CHECK-NEXT:    andq %r10, %r11165; CHECK-NEXT:    andq %r10, %rcx166; CHECK-NEXT:    xorq %r9, %rdx167; CHECK-NEXT:    xorq %r8, %rsi168; CHECK-NEXT:    xorq %rax, %rdi169; CHECK-NEXT:    cmpq %rdi, %rax170; CHECK-NEXT:    sbbq %rsi, %r8171; CHECK-NEXT:    sbbq %rdx, %r9172; CHECK-NEXT:    sbbq %rcx, %r11173; CHECK-NEXT:    setb %al174; CHECK-NEXT:    retq175  %a = call i255 @llvm.ctpop.i255(i255 %x)176  %b = trunc i255 %a to i8 ; largest value from ctpop is 255, fits in 8 bits.177  %c = icmp eq i8 %b, 1178  ret i1 %c179}180declare i255 @llvm.ctpop.i255(i255)181