1; RUN: llc < %s -march=r600 -mcpu=redwood | FileCheck --check-prefix=R600 %s
2; RUN: llc < %s -march=amdgcn -mcpu=SI -verify-machineinstrs | FileCheck --check-prefix=SI %s
3; RUN: llc < %s -march=amdgcn -mcpu=tonga -verify-machineinstrs | FileCheck --check-prefix=SI %s
4
5; BFI_INT Definition pattern from ISA docs
6; (y & x) | (z & ~x)
7;
8; R600: {{^}}bfi_def:
9; R600: BFI_INT
10; SI:   @bfi_def
11; SI:   v_bfi_b32
12define void @bfi_def(i32 addrspace(1)* %out, i32 %x, i32 %y, i32 %z) {
13entry:
14  %0 = xor i32 %x, -1
15  %1 = and i32 %z, %0
16  %2 = and i32 %y, %x
17  %3 = or i32 %1, %2
18  store i32 %3, i32 addrspace(1)* %out
19  ret void
20}
21
22; SHA-256 Ch function
23; z ^ (x & (y ^ z))
24; R600: {{^}}bfi_sha256_ch:
25; R600: BFI_INT
26; SI:   @bfi_sha256_ch
27; SI:   v_bfi_b32
28define void @bfi_sha256_ch(i32 addrspace(1)* %out, i32 %x, i32 %y, i32 %z) {
29entry:
30  %0 = xor i32 %y, %z
31  %1 = and i32 %x, %0
32  %2 = xor i32 %z, %1
33  store i32 %2, i32 addrspace(1)* %out
34  ret void
35}
36
37; SHA-256 Ma function
38; ((x & z) | (y & (x | z)))
39; R600: {{^}}bfi_sha256_ma:
40; R600: XOR_INT * [[DST:T[0-9]+\.[XYZW]]], KC0[2].Z, KC0[2].W
41; R600: BFI_INT * {{T[0-9]+\.[XYZW]}}, {{[[DST]]|PV\.[XYZW]}}, KC0[3].X, KC0[2].W
42; SI: v_xor_b32_e32 [[DST:v[0-9]+]], {{s[0-9]+, v[0-9]+}}
43; SI: v_bfi_b32 {{v[0-9]+}}, [[DST]], {{s[0-9]+, v[0-9]+}}
44
45define void @bfi_sha256_ma(i32 addrspace(1)* %out, i32 %x, i32 %y, i32 %z) {
46entry:
47  %0 = and i32 %x, %z
48  %1 = or i32 %x, %z
49  %2 = and i32 %y, %1
50  %3 = or i32 %0, %2
51  store i32 %3, i32 addrspace(1)* %out
52  ret void
53}
54