120 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc -mtriple=x86_64-unknown-unknown -show-mc-encoding < %s | FileCheck %s3 4; Test that the direct object emission selects the 'and' variant with 8-bit5; immediate.6; We used to get this wrong when using direct object emission, but not when7; reading assembly.8 9define void @f1() nounwind {10; CHECK-LABEL: f1:11; CHECK: # %bb.0:12; CHECK-NEXT: pushq %rbp # encoding: [0x55]13; CHECK-NEXT: movq %rsp, %rbp # encoding: [0x48,0x89,0xe5]14; CHECK-NEXT: andq $-32, %rsp # encoding: [0x48,0x83,0xe4,0xe0]15; CHECK-NEXT: movq %rbp, %rsp # encoding: [0x48,0x89,0xec]16; CHECK-NEXT: popq %rbp # encoding: [0x5d]17; CHECK-NEXT: retq # encoding: [0xc3]18 %foo = alloca i8, align 3219 ret void20}21 22define void @f2(i16 %x, ptr%y) nounwind {23; CHECK-LABEL: f2:24; CHECK: # %bb.0:25; CHECK-NEXT: andl $1, %edi # encoding: [0x83,0xe7,0x01]26; CHECK-NEXT: movb %dil, (%rsi) # encoding: [0x40,0x88,0x3e]27; CHECK-NEXT: retq # encoding: [0xc3]28 %c = trunc i16 %x to i129 store i1 %c, ptr %y30 ret void31}32 33define void @f3(i32 %x, ptr%y) nounwind {34; CHECK-LABEL: f3:35; CHECK: # %bb.0:36; CHECK-NEXT: andl $1, %edi # encoding: [0x83,0xe7,0x01]37; CHECK-NEXT: movb %dil, (%rsi) # encoding: [0x40,0x88,0x3e]38; CHECK-NEXT: retq # encoding: [0xc3]39 %c = trunc i32 %x to i140 store i1 %c, ptr %y41 ret void42}43 44; The immediate (0x0ffffff0) can be made into an i8 by making it negative.45 46define i32 @lopped32_32to8(i32 %x) {47; CHECK-LABEL: lopped32_32to8:48; CHECK: # %bb.0:49; CHECK-NEXT: movl %edi, %eax # encoding: [0x89,0xf8]50; CHECK-NEXT: shrl $4, %eax # encoding: [0xc1,0xe8,0x04]51; CHECK-NEXT: andl $-16, %eax # encoding: [0x83,0xe0,0xf0]52; CHECK-NEXT: retq # encoding: [0xc3]53 %shr = lshr i32 %x, 454 %and = and i32 %shr, 26843544055 ret i32 %and56}57 58; The immediate (0x0ffffff0) can be made into an i8 by making it negative.59 60define i64 @lopped64_32to8(i64 %x) {61; CHECK-LABEL: lopped64_32to8:62; CHECK: # %bb.0:63; CHECK-NEXT: movq %rdi, %rax # encoding: [0x48,0x89,0xf8]64; CHECK-NEXT: shrq $36, %rax # encoding: [0x48,0xc1,0xe8,0x24]65; CHECK-NEXT: andl $-16, %eax # encoding: [0x83,0xe0,0xf0]66; CHECK-NEXT: retq # encoding: [0xc3]67 %shr = lshr i64 %x, 3668 %and = and i64 %shr, 26843544069 ret i64 %and70}71 72; The immediate (0x0ffffffffffffff0) can be made into an i8 by making it negative.73 74define i64 @lopped64_64to8(i64 %x) {75; CHECK-LABEL: lopped64_64to8:76; CHECK: # %bb.0:77; CHECK-NEXT: movq %rdi, %rax # encoding: [0x48,0x89,0xf8]78; CHECK-NEXT: shrq $4, %rax # encoding: [0x48,0xc1,0xe8,0x04]79; CHECK-NEXT: andq $-16, %rax # encoding: [0x48,0x83,0xe0,0xf0]80; CHECK-NEXT: retq # encoding: [0xc3]81 %shr = lshr i64 %x, 482 %and = and i64 %shr, 115292150460684696083 ret i64 %and84}85 86; The immediate (0x0ffffffffff0fff0) can be made into an i32 by making it negative.87 88define i64 @lopped64_64to32(i64 %x) {89; CHECK-LABEL: lopped64_64to32:90; CHECK: # %bb.0:91; CHECK-NEXT: movq %rdi, %rax # encoding: [0x48,0x89,0xf8]92; CHECK-NEXT: shrq $4, %rax # encoding: [0x48,0xc1,0xe8,0x04]93; CHECK-NEXT: andq $-983056, %rax # encoding: [0x48,0x25,0xf0,0xff,0xf0,0xff]94; CHECK-NEXT: # imm = 0xFFF0FFF095; CHECK-NEXT: retq # encoding: [0xc3]96 %shr = lshr i64 %x, 497 %and = and i64 %shr, 115292150460586392098 ret i64 %and99}100 101; The transform is not limited to shifts - computeKnownBits() knows the top 4 bits102; must be cleared, so 0x0fffff80 can become 0x80 sign-extended.103 104define i32 @shrinkAndKnownBits(i32 %x) {105; CHECK-LABEL: shrinkAndKnownBits:106; CHECK: # %bb.0:107; CHECK-NEXT: movl %edi, %ecx # encoding: [0x89,0xf9]108; CHECK-NEXT: movl $4042322161, %eax # encoding: [0xb8,0xf1,0xf0,0xf0,0xf0]109; CHECK-NEXT: # imm = 0xF0F0F0F1110; CHECK-NEXT: imulq %rcx, %rax # encoding: [0x48,0x0f,0xaf,0xc1]111; CHECK-NEXT: shrq $36, %rax # encoding: [0x48,0xc1,0xe8,0x24]112; CHECK-NEXT: andl $-128, %eax # encoding: [0x83,0xe0,0x80]113; CHECK-NEXT: # kill: def $eax killed $eax killed $rax114; CHECK-NEXT: retq # encoding: [0xc3]115 %div = udiv i32 %x, 17116 %and = and i32 %div, 268435328117 ret i32 %and118}119 120