Index: test/CodeGen/AArch64/unfold-masked-merge.ll =================================================================== --- /dev/null +++ test/CodeGen/AArch64/unfold-masked-merge.ll @@ -0,0 +1,183 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s + +; https://bugs.llvm.org/show_bug.cgi?id=37104 + +define i32 @out(i32 %x, i32 %y, i32 %mask) { +; CHECK-LABEL: out: +; CHECK: // %bb.0: +; CHECK-NEXT: and w8, w0, w2 +; CHECK-NEXT: bic w9, w1, w2 +; CHECK-NEXT: orr w0, w8, w9 +; CHECK-NEXT: ret + %mx = and i32 %x, %mask + %notmask = xor i32 %mask, -1 + %my = and i32 %y, %notmask + %r = or i32 %mx, %my + ret i32 %r +} + +define i32 @out_constmask(i32 %x, i32 %y) { +; CHECK-LABEL: out_constmask: +; CHECK: // %bb.0: +; CHECK-NEXT: lsr w8, w0, #8 +; CHECK-NEXT: bfi w1, w8, #8, #16 +; CHECK-NEXT: mov w0, w1 +; CHECK-NEXT: ret + %mx = and i32 %x, 16776960 + %my = and i32 %y, -16776961 + %r = or i32 %mx, %my + ret i32 %r +} + +define <4 x i32> @out_vec(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-LABEL: out_vec: +; CHECK: // %bb.0: +; CHECK-NEXT: bsl v2.16b, v0.16b, v1.16b +; CHECK-NEXT: mov v0.16b, v2.16b +; CHECK-NEXT: ret + %mx = and <4 x i32> %x, %mask + %notmask = xor <4 x i32> %mask, + %my = and <4 x i32> %y, %notmask + %r = or <4 x i32> %mx, %my + ret <4 x i32> %r +} + +define <4 x i32> @out_vec_undef(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-LABEL: out_vec_undef: +; CHECK: // %bb.0: +; CHECK-NEXT: bsl v2.16b, v0.16b, v1.16b +; CHECK-NEXT: mov v0.16b, v2.16b +; CHECK-NEXT: ret + %mx = and <4 x i32> %x, %mask + %notmask = xor <4 x i32> %mask, + %my = and <4 x i32> %y, %notmask + %r = or <4 x i32> %mx, %my + ret <4 x i32> %r +} + +define <4 x i32> @out_vec_constmask_splat(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-LABEL: out_vec_constmask_splat: +; CHECK: // %bb.0: +; CHECK-NEXT: movi v2.2d, #0xffff0000ffff00 +; CHECK-NEXT: bsl v2.16b, v0.16b, v1.16b +; CHECK-NEXT: mov v0.16b, v2.16b +; CHECK-NEXT: ret + %mx = and <4 x i32> %x, + %my = and <4 x i32> %y, + %r = or <4 x i32> %mx, %my + ret <4 x i32> %r +} + +define <4 x i32> @out_vec_constmask_undef(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-LABEL: out_vec_constmask_undef: +; CHECK: // %bb.0: +; CHECK-NEXT: movi v2.2d, #0xffff0000ffff00 +; CHECK-NEXT: movi v3.2d, #0xff0000ffff0000ff +; CHECK-NEXT: and v0.16b, v0.16b, v2.16b +; CHECK-NEXT: and v1.16b, v1.16b, v3.16b +; CHECK-NEXT: orr v0.16b, v0.16b, v1.16b +; CHECK-NEXT: ret + %mx = and <4 x i32> %x, + %my = and <4 x i32> %y, + %r = or <4 x i32> %mx, %my + ret <4 x i32> %r +} + +define <4 x i32> @out_vec_constmask_nonsplat(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-LABEL: out_vec_constmask_nonsplat: +; CHECK: // %bb.0: +; CHECK-NEXT: movi v2.2d, #0xff00ff00ffff00 +; CHECK-NEXT: bsl v2.16b, v0.16b, v1.16b +; CHECK-NEXT: mov v0.16b, v2.16b +; CHECK-NEXT: ret + %mx = and <4 x i32> %x, + %my = and <4 x i32> %y, + %r = or <4 x i32> %mx, %my + ret <4 x i32> %r +} + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Should be the same as the previous one. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +define i32 @in(i32 %x, i32 %y, i32 %mask) { +; CHECK-LABEL: in: +; CHECK: // %bb.0: +; CHECK-NEXT: eor w8, w0, w1 +; CHECK-NEXT: and w8, w8, w2 +; CHECK-NEXT: eor w0, w8, w1 +; CHECK-NEXT: ret + %n0 = xor i32 %x, %y + %n1 = and i32 %n0, %mask + %r = xor i32 %n1, %y + ret i32 %r +} + +define i32 @in_constmask(i32 %x, i32 %y) { +; CHECK-LABEL: in_constmask: +; CHECK: // %bb.0: +; CHECK-NEXT: eor w8, w0, w1 +; CHECK-NEXT: and w8, w8, #0xffff00 +; CHECK-NEXT: eor w0, w8, w1 +; CHECK-NEXT: ret + %n0 = xor i32 %x, %y + %n1 = and i32 %n0, 16776960 + %r = xor i32 %n1, %y + ret i32 %r +} + +define <4 x i32> @in_vec(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-LABEL: in_vec: +; CHECK: // %bb.0: +; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b +; CHECK-NEXT: and v0.16b, v0.16b, v2.16b +; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b +; CHECK-NEXT: ret + %n0 = xor <4 x i32> %x, %y + %n1 = and <4 x i32> %n0, %mask + %r = xor <4 x i32> %n1, %y + ret <4 x i32> %r +} + +define <4 x i32> @in_vec_constmask_splat(<4 x i32> %x, <4 x i32> %y) { +; CHECK-LABEL: in_vec_constmask_splat: +; CHECK: // %bb.0: +; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b +; CHECK-NEXT: movi v2.2d, #0xffff0000ffff00 +; CHECK-NEXT: and v0.16b, v0.16b, v2.16b +; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b +; CHECK-NEXT: ret + %n0 = xor <4 x i32> %x, %y + %n1 = and <4 x i32> %n0, + %r = xor <4 x i32> %n1, %y + ret <4 x i32> %r +} + +define <4 x i32> @in_vec_constmask_undef(<4 x i32> %x, <4 x i32> %y) { +; CHECK-LABEL: in_vec_constmask_undef: +; CHECK: // %bb.0: +; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b +; CHECK-NEXT: movi v2.2d, #0xffff0000ffff00 +; CHECK-NEXT: and v0.16b, v0.16b, v2.16b +; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b +; CHECK-NEXT: ret + %n0 = xor <4 x i32> %x, %y + %n1 = and <4 x i32> %n0, + %r = xor <4 x i32> %n1, %y + ret <4 x i32> %r +} + +define <4 x i32> @in_vec_constmask_nonsplat(<4 x i32> %x, <4 x i32> %y) { +; CHECK-LABEL: in_vec_constmask_nonsplat: +; CHECK: // %bb.0: +; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b +; CHECK-NEXT: movi v2.2d, #0xff00ff00ffff00 +; CHECK-NEXT: and v0.16b, v0.16b, v2.16b +; CHECK-NEXT: eor v0.16b, v0.16b, v1.16b +; CHECK-NEXT: ret + %n0 = xor <4 x i32> %x, %y + %n1 = and <4 x i32> %n0, + %r = xor <4 x i32> %n1, %y + ret <4 x i32> %r +} Index: test/CodeGen/X86/unfold-masked-merge-scalar.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/unfold-masked-merge-scalar.ll @@ -0,0 +1,100 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi < %s | FileCheck %s --check-prefix=CHECK-NOBMI +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi < %s | FileCheck %s --check-prefix=CHECK-BMI + +; https://bugs.llvm.org/show_bug.cgi?id=37104 + +define i32 @out(i32 %x, i32 %y, i32 %mask) { +; CHECK-NOBMI-LABEL: out: +; CHECK-NOBMI: # %bb.0: +; CHECK-NOBMI-NEXT: andl %edx, %edi +; CHECK-NOBMI-NEXT: notl %edx +; CHECK-NOBMI-NEXT: andl %esi, %edx +; CHECK-NOBMI-NEXT: orl %edi, %edx +; CHECK-NOBMI-NEXT: movl %edx, %eax +; CHECK-NOBMI-NEXT: retq +; +; CHECK-BMI-LABEL: out: +; CHECK-BMI: # %bb.0: +; CHECK-BMI-NEXT: andl %edx, %edi +; CHECK-BMI-NEXT: andnl %esi, %edx, %eax +; CHECK-BMI-NEXT: orl %edi, %eax +; CHECK-BMI-NEXT: retq + %mx = and i32 %x, %mask + %notmask = xor i32 %mask, -1 + %my = and i32 %y, %notmask + %r = or i32 %mx, %my + ret i32 %r +} + +define i32 @out_constmask(i32 %x, i32 %y) { +; CHECK-NOBMI-LABEL: out_constmask: +; CHECK-NOBMI: # %bb.0: +; CHECK-NOBMI-NEXT: # kill: def $esi killed $esi def $rsi +; CHECK-NOBMI-NEXT: # kill: def $edi killed $edi def $rdi +; CHECK-NOBMI-NEXT: andl $16776960, %edi # imm = 0xFFFF00 +; CHECK-NOBMI-NEXT: andl $-16776961, %esi # imm = 0xFF0000FF +; CHECK-NOBMI-NEXT: leal (%rsi,%rdi), %eax +; CHECK-NOBMI-NEXT: retq +; +; CHECK-BMI-LABEL: out_constmask: +; CHECK-BMI: # %bb.0: +; CHECK-BMI-NEXT: # kill: def $esi killed $esi def $rsi +; CHECK-BMI-NEXT: # kill: def $edi killed $edi def $rdi +; CHECK-BMI-NEXT: andl $16776960, %edi # imm = 0xFFFF00 +; CHECK-BMI-NEXT: andl $-16776961, %esi # imm = 0xFF0000FF +; CHECK-BMI-NEXT: leal (%rsi,%rdi), %eax +; CHECK-BMI-NEXT: retq + %mx = and i32 %x, 16776960 + %my = and i32 %y, -16776961 + %r = or i32 %mx, %my + ret i32 %r +} + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Should be the same as the previous one. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +define i32 @in(i32 %x, i32 %y, i32 %mask) { +; CHECK-NOBMI-LABEL: in: +; CHECK-NOBMI: # %bb.0: +; CHECK-NOBMI-NEXT: xorl %esi, %edi +; CHECK-NOBMI-NEXT: andl %edx, %edi +; CHECK-NOBMI-NEXT: xorl %esi, %edi +; CHECK-NOBMI-NEXT: movl %edi, %eax +; CHECK-NOBMI-NEXT: retq +; +; CHECK-BMI-LABEL: in: +; CHECK-BMI: # %bb.0: +; CHECK-BMI-NEXT: xorl %esi, %edi +; CHECK-BMI-NEXT: andl %edx, %edi +; CHECK-BMI-NEXT: xorl %esi, %edi +; CHECK-BMI-NEXT: movl %edi, %eax +; CHECK-BMI-NEXT: retq + %n0 = xor i32 %x, %y + %n1 = and i32 %n0, %mask + %r = xor i32 %n1, %y + ret i32 %r +} + +define i32 @in_constmask(i32 %x, i32 %y) { +; CHECK-NOBMI-LABEL: in_constmask: +; CHECK-NOBMI: # %bb.0: +; CHECK-NOBMI-NEXT: xorl %esi, %edi +; CHECK-NOBMI-NEXT: andl $16776960, %edi # imm = 0xFFFF00 +; CHECK-NOBMI-NEXT: xorl %esi, %edi +; CHECK-NOBMI-NEXT: movl %edi, %eax +; CHECK-NOBMI-NEXT: retq +; +; CHECK-BMI-LABEL: in_constmask: +; CHECK-BMI: # %bb.0: +; CHECK-BMI-NEXT: xorl %esi, %edi +; CHECK-BMI-NEXT: andl $16776960, %edi # imm = 0xFFFF00 +; CHECK-BMI-NEXT: xorl %esi, %edi +; CHECK-BMI-NEXT: movl %edi, %eax +; CHECK-BMI-NEXT: retq + %n0 = xor i32 %x, %y + %n1 = and i32 %n0, 16776960 + %r = xor i32 %n1, %y + ret i32 %r +} Index: test/CodeGen/X86/unfold-masked-merge-vector.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/unfold-masked-merge-vector.ll @@ -0,0 +1,350 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-sse < %s | FileCheck %s --check-prefix=CHECK-NOSSE +; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+sse < %s | FileCheck %s --check-prefix=CHECK-SSE + +; https://bugs.llvm.org/show_bug.cgi?id=37104 + +define <4 x i32> @out_vec(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-NOSSE-LABEL: out_vec: +; CHECK-NOSSE: # %bb.0: +; CHECK-NOSSE-NEXT: pushq %rbx +; CHECK-NOSSE-NEXT: .cfi_def_cfa_offset 16 +; CHECK-NOSSE-NEXT: .cfi_offset %rbx, -16 +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r10d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r11d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %ebx +; CHECK-NOSSE-NEXT: andl %ebx, %r8d +; CHECK-NOSSE-NEXT: andl %eax, %ecx +; CHECK-NOSSE-NEXT: andl %r11d, %edx +; CHECK-NOSSE-NEXT: andl %r10d, %esi +; CHECK-NOSSE-NEXT: notl %r11d +; CHECK-NOSSE-NEXT: notl %eax +; CHECK-NOSSE-NEXT: notl %ebx +; CHECK-NOSSE-NEXT: notl %r10d +; CHECK-NOSSE-NEXT: andl %r9d, %r10d +; CHECK-NOSSE-NEXT: orl %esi, %r10d +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %ebx +; CHECK-NOSSE-NEXT: orl %r8d, %ebx +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: orl %ecx, %eax +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %r11d +; CHECK-NOSSE-NEXT: orl %edx, %r11d +; CHECK-NOSSE-NEXT: movl %ebx, 12(%rdi) +; CHECK-NOSSE-NEXT: movl %eax, 8(%rdi) +; CHECK-NOSSE-NEXT: movl %r11d, 4(%rdi) +; CHECK-NOSSE-NEXT: movl %r10d, (%rdi) +; CHECK-NOSSE-NEXT: movq %rdi, %rax +; CHECK-NOSSE-NEXT: popq %rbx +; CHECK-NOSSE-NEXT: retq +; +; CHECK-SSE-LABEL: out_vec: +; CHECK-SSE: # %bb.0: +; CHECK-SSE-NEXT: andps %xmm2, %xmm0 +; CHECK-SSE-NEXT: andnps %xmm1, %xmm2 +; CHECK-SSE-NEXT: orps %xmm2, %xmm0 +; CHECK-SSE-NEXT: retq + %mx = and <4 x i32> %x, %mask + %notmask = xor <4 x i32> %mask, + %my = and <4 x i32> %y, %notmask + %r = or <4 x i32> %mx, %my + ret <4 x i32> %r +} + +define <4 x i32> @out_vec_undef(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-NOSSE-LABEL: out_vec_undef: +; CHECK-NOSSE: # %bb.0: +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r10d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r11d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: andl %eax, %r8d +; CHECK-NOSSE-NEXT: andl %r11d, %edx +; CHECK-NOSSE-NEXT: andl %r10d, %esi +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %ecx +; CHECK-NOSSE-NEXT: notl %r11d +; CHECK-NOSSE-NEXT: notl %eax +; CHECK-NOSSE-NEXT: notl %r10d +; CHECK-NOSSE-NEXT: andl %r9d, %r10d +; CHECK-NOSSE-NEXT: orl %esi, %r10d +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: orl %r8d, %eax +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %r11d +; CHECK-NOSSE-NEXT: orl %edx, %r11d +; CHECK-NOSSE-NEXT: movl %ecx, 8(%rdi) +; CHECK-NOSSE-NEXT: movl %eax, 12(%rdi) +; CHECK-NOSSE-NEXT: movl %r11d, 4(%rdi) +; CHECK-NOSSE-NEXT: movl %r10d, (%rdi) +; CHECK-NOSSE-NEXT: movq %rdi, %rax +; CHECK-NOSSE-NEXT: retq +; +; CHECK-SSE-LABEL: out_vec_undef: +; CHECK-SSE: # %bb.0: +; CHECK-SSE-NEXT: andps %xmm2, %xmm0 +; CHECK-SSE-NEXT: andnps %xmm1, %xmm2 +; CHECK-SSE-NEXT: orps %xmm2, %xmm0 +; CHECK-SSE-NEXT: retq + %mx = and <4 x i32> %x, %mask + %notmask = xor <4 x i32> %mask, + %my = and <4 x i32> %y, %notmask + %r = or <4 x i32> %mx, %my + ret <4 x i32> %r +} + +define <4 x i32> @out_vec_constmask_splat(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-NOSSE-LABEL: out_vec_constmask_splat: +; CHECK-NOSSE: # %bb.0: +; CHECK-NOSSE-NEXT: andl $16776960, %r8d # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16776960, %ecx # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16776960, %edx # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16776960, %esi # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: movl $-16776961, %eax # imm = 0xFF0000FF +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r10d +; CHECK-NOSSE-NEXT: andl %eax, %r10d +; CHECK-NOSSE-NEXT: orl %r8d, %r10d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r8d +; CHECK-NOSSE-NEXT: andl %eax, %r8d +; CHECK-NOSSE-NEXT: orl %ecx, %r8d +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: orl %edx, %eax +; CHECK-NOSSE-NEXT: andl $-16776961, %r9d # imm = 0xFF0000FF +; CHECK-NOSSE-NEXT: orl %esi, %r9d +; CHECK-NOSSE-NEXT: movl %r10d, 12(%rdi) +; CHECK-NOSSE-NEXT: movl %r8d, 8(%rdi) +; CHECK-NOSSE-NEXT: movl %eax, 4(%rdi) +; CHECK-NOSSE-NEXT: movl %r9d, (%rdi) +; CHECK-NOSSE-NEXT: movq %rdi, %rax +; CHECK-NOSSE-NEXT: retq +; +; CHECK-SSE-LABEL: out_vec_constmask_splat: +; CHECK-SSE: # %bb.0: +; CHECK-SSE-NEXT: movaps {{.*#+}} xmm2 = [0,255,255,0,0,255,255,0,0,255,255,0,0,255,255,0] +; CHECK-SSE-NEXT: andps %xmm2, %xmm0 +; CHECK-SSE-NEXT: andnps %xmm1, %xmm2 +; CHECK-SSE-NEXT: orps %xmm2, %xmm0 +; CHECK-SSE-NEXT: retq + %mx = and <4 x i32> %x, + %my = and <4 x i32> %y, + %r = or <4 x i32> %mx, %my + ret <4 x i32> %r +} + +define <4 x i32> @out_vec_constmask_undef(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-NOSSE-LABEL: out_vec_constmask_undef: +; CHECK-NOSSE: # %bb.0: +; CHECK-NOSSE-NEXT: andl $16776960, %r8d # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16776960, %edx # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16776960, %esi # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: movl $-16776961, %eax # imm = 0xFF0000FF +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %ecx +; CHECK-NOSSE-NEXT: andl %eax, %ecx +; CHECK-NOSSE-NEXT: orl %r8d, %ecx +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: orl %edx, %eax +; CHECK-NOSSE-NEXT: andl $-16776961, %r9d # imm = 0xFF0000FF +; CHECK-NOSSE-NEXT: orl %esi, %r9d +; CHECK-NOSSE-NEXT: movl %ecx, 12(%rdi) +; CHECK-NOSSE-NEXT: movl %eax, 4(%rdi) +; CHECK-NOSSE-NEXT: movl %r9d, (%rdi) +; CHECK-NOSSE-NEXT: movl $0, 8(%rdi) +; CHECK-NOSSE-NEXT: movq %rdi, %rax +; CHECK-NOSSE-NEXT: retq +; +; CHECK-SSE-LABEL: out_vec_constmask_undef: +; CHECK-SSE: # %bb.0: +; CHECK-SSE-NEXT: movaps {{.*#+}} xmm2 = [0,255,255,0,0,255,255,0,255,255,255,255,0,255,255,0] +; CHECK-SSE-NEXT: andps %xmm2, %xmm0 +; CHECK-SSE-NEXT: andnps %xmm1, %xmm2 +; CHECK-SSE-NEXT: orps %xmm2, %xmm0 +; CHECK-SSE-NEXT: retq + %mx = and <4 x i32> %x, + %my = and <4 x i32> %y, + %r = or <4 x i32> %mx, %my + ret <4 x i32> %r +} + +define <4 x i32> @out_vec_constmask_nonsplat(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-NOSSE-LABEL: out_vec_constmask_nonsplat: +; CHECK-NOSSE: # %bb.0: +; CHECK-NOSSE-NEXT: andl $16711935, %r8d # imm = 0xFF00FF +; CHECK-NOSSE-NEXT: andl $16776960, %ecx # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16711935, %edx # imm = 0xFF00FF +; CHECK-NOSSE-NEXT: andl $16776960, %esi # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: movl $-16711936, %r11d # imm = 0xFF00FF00 +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r10d +; CHECK-NOSSE-NEXT: andl %r11d, %r10d +; CHECK-NOSSE-NEXT: orl %r8d, %r10d +; CHECK-NOSSE-NEXT: movl $-16776961, %eax # imm = 0xFF0000FF +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: orl %ecx, %eax +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %r11d +; CHECK-NOSSE-NEXT: orl %edx, %r11d +; CHECK-NOSSE-NEXT: andl $-16776961, %r9d # imm = 0xFF0000FF +; CHECK-NOSSE-NEXT: orl %esi, %r9d +; CHECK-NOSSE-NEXT: movl %r10d, 12(%rdi) +; CHECK-NOSSE-NEXT: movl %eax, 8(%rdi) +; CHECK-NOSSE-NEXT: movl %r11d, 4(%rdi) +; CHECK-NOSSE-NEXT: movl %r9d, (%rdi) +; CHECK-NOSSE-NEXT: movq %rdi, %rax +; CHECK-NOSSE-NEXT: retq +; +; CHECK-SSE-LABEL: out_vec_constmask_nonsplat: +; CHECK-SSE: # %bb.0: +; CHECK-SSE-NEXT: movaps {{.*#+}} xmm2 = [0,255,255,0,255,0,255,0,0,255,255,0,255,0,255,0] +; CHECK-SSE-NEXT: andps %xmm2, %xmm0 +; CHECK-SSE-NEXT: andnps %xmm1, %xmm2 +; CHECK-SSE-NEXT: orps %xmm2, %xmm0 +; CHECK-SSE-NEXT: retq + %mx = and <4 x i32> %x, + %my = and <4 x i32> %y, + %r = or <4 x i32> %mx, %my + ret <4 x i32> %r +} + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Should be the same as the previous one. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +define <4 x i32> @in_vec(<4 x i32> %x, <4 x i32> %y, <4 x i32> %mask) { +; CHECK-NOSSE-LABEL: in_vec: +; CHECK-NOSSE: # %bb.0: +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r10d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r11d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: xorl %r9d, %esi +; CHECK-NOSSE-NEXT: xorl %eax, %edx +; CHECK-NOSSE-NEXT: xorl %r11d, %ecx +; CHECK-NOSSE-NEXT: xorl %r10d, %r8d +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %r8d +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %ecx +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %edx +; CHECK-NOSSE-NEXT: andl {{[0-9]+}}(%rsp), %esi +; CHECK-NOSSE-NEXT: xorl %r9d, %esi +; CHECK-NOSSE-NEXT: xorl %eax, %edx +; CHECK-NOSSE-NEXT: xorl %r11d, %ecx +; CHECK-NOSSE-NEXT: xorl %r10d, %r8d +; CHECK-NOSSE-NEXT: movl %r8d, 12(%rdi) +; CHECK-NOSSE-NEXT: movl %ecx, 8(%rdi) +; CHECK-NOSSE-NEXT: movl %edx, 4(%rdi) +; CHECK-NOSSE-NEXT: movl %esi, (%rdi) +; CHECK-NOSSE-NEXT: movq %rdi, %rax +; CHECK-NOSSE-NEXT: retq +; +; CHECK-SSE-LABEL: in_vec: +; CHECK-SSE: # %bb.0: +; CHECK-SSE-NEXT: xorps %xmm1, %xmm0 +; CHECK-SSE-NEXT: andps %xmm2, %xmm0 +; CHECK-SSE-NEXT: xorps %xmm1, %xmm0 +; CHECK-SSE-NEXT: retq + %n0 = xor <4 x i32> %x, %y + %n1 = and <4 x i32> %n0, %mask + %r = xor <4 x i32> %n1, %y + ret <4 x i32> %r +} + +define <4 x i32> @in_vec_constmask_splat(<4 x i32> %x, <4 x i32> %y) { +; CHECK-NOSSE-LABEL: in_vec_constmask_splat: +; CHECK-NOSSE: # %bb.0: +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r10d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r11d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: xorl %r9d, %esi +; CHECK-NOSSE-NEXT: xorl %eax, %edx +; CHECK-NOSSE-NEXT: xorl %r11d, %ecx +; CHECK-NOSSE-NEXT: xorl %r10d, %r8d +; CHECK-NOSSE-NEXT: andl $16776960, %r8d # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16776960, %ecx # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16776960, %edx # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16776960, %esi # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: xorl %r9d, %esi +; CHECK-NOSSE-NEXT: xorl %eax, %edx +; CHECK-NOSSE-NEXT: xorl %r11d, %ecx +; CHECK-NOSSE-NEXT: xorl %r10d, %r8d +; CHECK-NOSSE-NEXT: movl %r8d, 12(%rdi) +; CHECK-NOSSE-NEXT: movl %ecx, 8(%rdi) +; CHECK-NOSSE-NEXT: movl %edx, 4(%rdi) +; CHECK-NOSSE-NEXT: movl %esi, (%rdi) +; CHECK-NOSSE-NEXT: movq %rdi, %rax +; CHECK-NOSSE-NEXT: retq +; +; CHECK-SSE-LABEL: in_vec_constmask_splat: +; CHECK-SSE: # %bb.0: +; CHECK-SSE-NEXT: xorps %xmm1, %xmm0 +; CHECK-SSE-NEXT: andps {{.*}}(%rip), %xmm0 +; CHECK-SSE-NEXT: xorps %xmm1, %xmm0 +; CHECK-SSE-NEXT: retq + %n0 = xor <4 x i32> %x, %y + %n1 = and <4 x i32> %n0, + %r = xor <4 x i32> %n1, %y + ret <4 x i32> %r +} + +define <4 x i32> @in_vec_constmask_undef(<4 x i32> %x, <4 x i32> %y) { +; CHECK-NOSSE-LABEL: in_vec_constmask_undef: +; CHECK-NOSSE: # %bb.0: +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r10d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %ecx +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: xorl %r9d, %esi +; CHECK-NOSSE-NEXT: xorl %eax, %edx +; CHECK-NOSSE-NEXT: xorl %ecx, %r8d +; CHECK-NOSSE-NEXT: andl $16776960, %r8d # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16776960, %edx # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16776960, %esi # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: xorl %r9d, %esi +; CHECK-NOSSE-NEXT: xorl %eax, %edx +; CHECK-NOSSE-NEXT: xorl %ecx, %r8d +; CHECK-NOSSE-NEXT: movl %r10d, 8(%rdi) +; CHECK-NOSSE-NEXT: movl %r8d, 12(%rdi) +; CHECK-NOSSE-NEXT: movl %edx, 4(%rdi) +; CHECK-NOSSE-NEXT: movl %esi, (%rdi) +; CHECK-NOSSE-NEXT: movq %rdi, %rax +; CHECK-NOSSE-NEXT: retq +; +; CHECK-SSE-LABEL: in_vec_constmask_undef: +; CHECK-SSE: # %bb.0: +; CHECK-SSE-NEXT: xorps %xmm1, %xmm0 +; CHECK-SSE-NEXT: andps {{.*}}(%rip), %xmm0 +; CHECK-SSE-NEXT: xorps %xmm1, %xmm0 +; CHECK-SSE-NEXT: retq + %n0 = xor <4 x i32> %x, %y + %n1 = and <4 x i32> %n0, + %r = xor <4 x i32> %n1, %y + ret <4 x i32> %r +} + +define <4 x i32> @in_vec_constmask_nonsplat(<4 x i32> %x, <4 x i32> %y) { +; CHECK-NOSSE-LABEL: in_vec_constmask_nonsplat: +; CHECK-NOSSE: # %bb.0: +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r10d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %r11d +; CHECK-NOSSE-NEXT: movl {{[0-9]+}}(%rsp), %eax +; CHECK-NOSSE-NEXT: xorl %r9d, %esi +; CHECK-NOSSE-NEXT: xorl %eax, %edx +; CHECK-NOSSE-NEXT: xorl %r11d, %ecx +; CHECK-NOSSE-NEXT: xorl %r10d, %r8d +; CHECK-NOSSE-NEXT: andl $16711935, %r8d # imm = 0xFF00FF +; CHECK-NOSSE-NEXT: andl $16776960, %ecx # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: andl $16711935, %edx # imm = 0xFF00FF +; CHECK-NOSSE-NEXT: andl $16776960, %esi # imm = 0xFFFF00 +; CHECK-NOSSE-NEXT: xorl %r9d, %esi +; CHECK-NOSSE-NEXT: xorl %eax, %edx +; CHECK-NOSSE-NEXT: xorl %r11d, %ecx +; CHECK-NOSSE-NEXT: xorl %r10d, %r8d +; CHECK-NOSSE-NEXT: movl %r8d, 12(%rdi) +; CHECK-NOSSE-NEXT: movl %ecx, 8(%rdi) +; CHECK-NOSSE-NEXT: movl %edx, 4(%rdi) +; CHECK-NOSSE-NEXT: movl %esi, (%rdi) +; CHECK-NOSSE-NEXT: movq %rdi, %rax +; CHECK-NOSSE-NEXT: retq +; +; CHECK-SSE-LABEL: in_vec_constmask_nonsplat: +; CHECK-SSE: # %bb.0: +; CHECK-SSE-NEXT: xorps %xmm1, %xmm0 +; CHECK-SSE-NEXT: andps {{.*}}(%rip), %xmm0 +; CHECK-SSE-NEXT: xorps %xmm1, %xmm0 +; CHECK-SSE-NEXT: retq + %n0 = xor <4 x i32> %x, %y + %n1 = and <4 x i32> %n0, + %r = xor <4 x i32> %n1, %y + ret <4 x i32> %r +}