Skip to content

Commit 966a58e

Browse files
committed
[X86] Support matching VPTERNLOG when the root node is X86ISD::ANDNP.
1 parent a599e13 commit 966a58e

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

llvm/lib/Target/X86/X86ISelDAGToDAG.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3991,6 +3991,12 @@ bool X86DAGToDAGISel::tryVPTERNLOG(SDNode *N) {
39913991

39923992
switch (N->getOpcode()) {
39933993
default: llvm_unreachable("Unexpected opcode!");
3994+
case X86ISD::ANDNP:
3995+
if (A == N0)
3996+
Imm &= ~TernlogMagicA;
3997+
else
3998+
Imm = ~(Imm) & TernlogMagicA;
3999+
break;
39944000
case ISD::AND: Imm &= TernlogMagicA; break;
39954001
case ISD::OR: Imm |= TernlogMagicA; break;
39964002
case ISD::XOR: Imm ^= TernlogMagicA; break;
@@ -4592,6 +4598,11 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
45924598
return;
45934599
break;
45944600

4601+
case X86ISD::ANDNP:
4602+
if (tryVPTERNLOG(Node))
4603+
return;
4604+
break;
4605+
45954606
case ISD::AND:
45964607
if (NVT.isVector() && NVT.getVectorElementType() == MVT::i1) {
45974608
// Try to form a masked VPTESTM. Operands can be in either order.

llvm/test/CodeGen/X86/avx512vl-logic.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,7 @@ define <4 x i64> @ternlog_masky_xor_and_mask_ymm(<4 x i64> %x, <4 x i64> %y, <4
13011301
define <4 x i32> @ternlog_andn_or(<4 x i32> %x, <4 x i32> %y, <4 x i32> %z) {
13021302
; CHECK-LABEL: ternlog_andn_or:
13031303
; CHECK: ## %bb.0:
1304-
; CHECK-NEXT: vorps %xmm2, %xmm1, %xmm1
1305-
; CHECK-NEXT: vandnps %xmm1, %xmm0, %xmm0
1304+
; CHECK-NEXT: vpternlogd $14, %xmm2, %xmm1, %xmm0
13061305
; CHECK-NEXT: retq
13071306
%a = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
13081307
%b = or <4 x i32> %y, %z
@@ -1313,8 +1312,7 @@ define <4 x i32> @ternlog_andn_or(<4 x i32> %x, <4 x i32> %y, <4 x i32> %z) {
13131312
define <4 x i32> @ternlog_andn_or_2(<4 x i32> %x, <4 x i32> %y, <4 x i32> %z) {
13141313
; CHECK-LABEL: ternlog_andn_or_2:
13151314
; CHECK: ## %bb.0:
1316-
; CHECK-NEXT: vorps %xmm2, %xmm1, %xmm1
1317-
; CHECK-NEXT: vandnps %xmm0, %xmm1, %xmm0
1315+
; CHECK-NEXT: vpternlogd $16, %xmm2, %xmm1, %xmm0
13181316
; CHECK-NEXT: retq
13191317
%a = or <4 x i32> %y, %z
13201318
%b = xor <4 x i32> %a, <i32 -1, i32 -1, i32 -1, i32 -1>

0 commit comments

Comments
 (0)