xref: /llvm-project/llvm/test/CodeGen/X86/and-or-fold.ll (revision e529cda970e4422647bcc296cc306d08f2757be9)
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2; RUN: llc < %s -mtriple=i686-apple-darwin | FileCheck -check-prefix=DARWIN %s
3; RUN: opt < %s -O2 | llc -mtriple=x86_64-apple-darwin | FileCheck -check-prefix=DARWIN-OPT %s
4
5define i64 @or_and_fold(i64 %x, i64 %y) {
6; DARWIN-LABEL: or_and_fold:
7; DARWIN:       ## %bb.0:
8; DARWIN-NEXT:    movl {{[0-9]+}}(%esp), %eax
9; DARWIN-NEXT:    movl {{[0-9]+}}(%esp), %edx
10; DARWIN-NEXT:    retl
11;
12; DARWIN-OPT-LABEL: or_and_fold:
13; DARWIN-OPT:       ## %bb.0:
14; DARWIN-OPT-NEXT:    movq %rdi, %rax
15; DARWIN-OPT-NEXT:    retq
16  %and = and i64 %x, %y
17  %or = or i64 %x, %and
18  ret i64 %or
19}
20
21define i32 @or_and_trunc_fold(i64 %x, i64 %y) {
22; DARWIN-LABEL: or_and_trunc_fold:
23; DARWIN:       ## %bb.0:
24; DARWIN-NEXT:    movl {{[0-9]+}}(%esp), %eax
25; DARWIN-NEXT:    retl
26;
27; DARWIN-OPT-LABEL: or_and_trunc_fold:
28; DARWIN-OPT:       ## %bb.0:
29; DARWIN-OPT-NEXT:    movq %rdi, %rax
30; DARWIN-OPT-NEXT:    ## kill: def $eax killed $eax killed $rax
31; DARWIN-OPT-NEXT:    retq
32  %tx = trunc i64 %x to i32
33  %and = and i64 %x, %y
34  %tand = trunc i64 %and to i32
35  %or = or i32 %tx, %tand
36  ret i32 %or
37}
38
39; The dag combiner should fold together (x&127)|(y&16711680) -> (x|y)&c1
40; in this case.
41
42define i32 @test1(i32 %x, i16 %y) {
43; DARWIN-LABEL: test1:
44; DARWIN:       ## %bb.0:
45; DARWIN-NEXT:    movzwl {{[0-9]+}}(%esp), %ecx
46; DARWIN-NEXT:    movl {{[0-9]+}}(%esp), %eax
47; DARWIN-NEXT:    shll $16, %eax
48; DARWIN-NEXT:    orl %ecx, %eax
49; DARWIN-NEXT:    andl $16711807, %eax ## imm = 0xFF007F
50; DARWIN-NEXT:    retl
51;
52; DARWIN-OPT-LABEL: test1:
53; DARWIN-OPT:       ## %bb.0:
54; DARWIN-OPT-NEXT:    andl $127, %esi
55; DARWIN-OPT-NEXT:    movzbl %dil, %eax
56; DARWIN-OPT-NEXT:    shll $16, %eax
57; DARWIN-OPT-NEXT:    orl %esi, %eax
58; DARWIN-OPT-NEXT:    retq
59  %tmp1 = zext i16 %y to i32
60  %tmp2 = and i32 %tmp1, 127
61  %tmp4 = shl i32 %x, 16
62  %tmp5 = and i32 %tmp4, 16711680
63  %tmp6 = or i32 %tmp2, %tmp5
64  ret i32 %tmp6
65}
66
67; <rdar://problem/7529774> The optimizer shouldn't fold this into (and (or, C),  D)
68; if (C & D) == 0
69define i64 @test2(i64 %x) nounwind readnone ssp {
70; DARWIN-LABEL: test2:
71; DARWIN:       ## %bb.0: ## %entry
72; DARWIN-NEXT:    movl {{[0-9]+}}(%esp), %eax
73; DARWIN-NEXT:    orl $3, %eax
74; DARWIN-NEXT:    andl $123127, %eax ## imm = 0x1E0F7
75; DARWIN-NEXT:    xorl %edx, %edx
76; DARWIN-NEXT:    retl
77;
78; DARWIN-OPT-LABEL: test2:
79; DARWIN-OPT:       ## %bb.0: ## %entry
80; DARWIN-OPT-NEXT:    andl $123124, %edi ## imm = 0x1E0F4
81; DARWIN-OPT-NEXT:    leaq 3(%rdi), %rax
82; DARWIN-OPT-NEXT:    retq
83entry:
84  %tmp1 = and i64 %x, 123127
85  %tmp2 = or i64 %tmp1, 3
86  ret i64 %tmp2
87}
88