xref: /llvm-project/llvm/test/CodeGen/X86/not-and-simplify.ll (revision c22dc71b120b066c0066b8517014149a001cc2b0)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=-bmi | FileCheck %s --check-prefix=ALL
3; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+bmi | FileCheck %s --check-prefix=ALL
4
5; Clear high bits via shift, set them with xor (not), then mask them off.
6
7define i32 @shrink_xor_constant1(i32 %x) {
8; ALL-LABEL: shrink_xor_constant1:
9; ALL:       # %bb.0:
10; ALL-NEXT:    movl %edi, %eax
11; ALL-NEXT:    notl %eax
12; ALL-NEXT:    shrl $31, %eax
13; ALL-NEXT:    retq
14  %sh = lshr i32 %x, 31
15  %not = xor i32 %sh, -1
16  %and = and i32 %not, 1
17  ret i32 %and
18}
19
20define <4 x i32> @shrink_xor_constant1_splat(<4 x i32> %x) {
21; ALL-LABEL: shrink_xor_constant1_splat:
22; ALL:       # %bb.0:
23; ALL-NEXT:    pcmpeqd %xmm1, %xmm1
24; ALL-NEXT:    pxor %xmm1, %xmm0
25; ALL-NEXT:    psrld $31, %xmm0
26; ALL-NEXT:    retq
27  %sh = lshr <4 x i32> %x, <i32 31, i32 31, i32 31, i32 31>
28  %not = xor <4 x i32> %sh, <i32 -1, i32 -1, i32 -1, i32 -1>
29  %and = and <4 x i32> %not, <i32 1, i32 1, i32 1, i32 1>
30  ret <4 x i32> %and
31}
32
33; Clear low bits via shift, set them with xor (not), then mask them off.
34
35define i8 @shrink_xor_constant2(i8 %x) {
36; ALL-LABEL: shrink_xor_constant2:
37; ALL:       # %bb.0:
38; ALL-NEXT:    movl %edi, %eax
39; ALL-NEXT:    notb %al
40; ALL-NEXT:    shlb $5, %al
41; ALL-NEXT:    # kill: def $al killed $al killed $eax
42; ALL-NEXT:    retq
43  %sh = shl i8 %x, 5
44  %not = xor i8 %sh, -1
45  %and = and i8 %not, 224 ; 0xE0
46  ret i8 %and
47}
48
49define <16 x i8> @shrink_xor_constant2_splat(<16 x i8> %x) {
50; ALL-LABEL: shrink_xor_constant2_splat:
51; ALL:       # %bb.0:
52; ALL-NEXT:    movaps {{.*#+}} xmm0 = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
53; ALL-NEXT:    retq
54  %sh = shl <16 x i8> %x, <i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5>
55  %not = xor <16 x i8> %sh, <i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1, i8 -1>
56  %and = and <16 x i8> %not, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
57  ret <16 x i8> %and
58}
59
60