[llvm] 30211c4 - [X86] combineANDXORWithAllOnesIntoANDNP - add BROADCAST handling
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 30 08:32:03 PDT 2020
Author: Simon Pilgrim
Date: 2020-04-30T16:24:17+01:00
New Revision: 30211c47837ec7bd332e6da159647855e23a6aef
URL: https://github.com/llvm/llvm-project/commit/30211c47837ec7bd332e6da159647855e23a6aef
DIFF: https://github.com/llvm/llvm-project/commit/30211c47837ec7bd332e6da159647855e23a6aef.diff
LOG: [X86] combineANDXORWithAllOnesIntoANDNP - add BROADCAST handling
Fold BROADCAST(NOT(Y)) -> BROADCAST(Y) as part of finding a NOT inversion.
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/combine-bitselect.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 71515d960cd7..78015544c232 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -41249,10 +41249,27 @@ static SDValue combineANDXORWithAllOnesIntoANDNP(SDNode *N, SelectionDAG &DAG) {
SDValue N0 = N->getOperand(0);
SDValue N1 = N->getOperand(1);
- if (SDValue Not = IsNOT(N0, DAG)) {
+ auto GetNot = [&VT, &DAG](SDValue V) {
+ // Basic X = NOT(Y) detection.
+ if (SDValue Not = IsNOT(V, DAG))
+ return Not;
+ // Fold BROADCAST(NOT(Y)) -> BROADCAST(Y).
+ if (V.getOpcode() == X86ISD::VBROADCAST) {
+ SDValue Src = V.getOperand(0);
+ EVT SrcVT = Src.getValueType();
+ if (!SrcVT.isVector())
+ return SDValue();
+ if (SDValue Not = IsNOT(Src, DAG))
+ return DAG.getNode(X86ISD::VBROADCAST, SDLoc(V), VT,
+ DAG.getBitcast(SrcVT, Not));
+ }
+ return SDValue();
+ };
+
+ if (SDValue Not = GetNot(N0)) {
X = Not;
Y = N1;
- } else if (SDValue Not = IsNOT(N1, DAG)) {
+ } else if (SDValue Not = GetNot(N1)) {
X = Not;
Y = N0;
} else
diff --git a/llvm/test/CodeGen/X86/combine-bitselect.ll b/llvm/test/CodeGen/X86/combine-bitselect.ll
index 5945376ec9da..1fc18357ef7c 100644
--- a/llvm/test/CodeGen/X86/combine-bitselect.ll
+++ b/llvm/test/CodeGen/X86/combine-bitselect.ll
@@ -318,24 +318,18 @@ define <4 x i64> @bitselect_v4i64_broadcast_rrr(<4 x i64> %a0, <4 x i64> %a1, i6
; AVX2-LABEL: bitselect_v4i64_broadcast_rrr:
; AVX2: # %bb.0:
; AVX2-NEXT: vmovq %rdi, %xmm2
-; AVX2-NEXT: vpbroadcastq %xmm2, %ymm3
-; AVX2-NEXT: vpcmpeqd %xmm4, %xmm4, %xmm4
-; AVX2-NEXT: vpxor %xmm4, %xmm2, %xmm2
; AVX2-NEXT: vpbroadcastq %xmm2, %ymm2
-; AVX2-NEXT: vpand %ymm3, %ymm0, %ymm0
-; AVX2-NEXT: vpand %ymm2, %ymm1, %ymm1
+; AVX2-NEXT: vpand %ymm2, %ymm0, %ymm0
+; AVX2-NEXT: vpandn %ymm1, %ymm2, %ymm1
; AVX2-NEXT: vpor %ymm1, %ymm0, %ymm0
; AVX2-NEXT: retq
;
; AVX512F-LABEL: bitselect_v4i64_broadcast_rrr:
; AVX512F: # %bb.0:
; AVX512F-NEXT: vmovq %rdi, %xmm2
-; AVX512F-NEXT: vmovq %rdi, %xmm3
-; AVX512F-NEXT: vpbroadcastq %xmm3, %ymm3
-; AVX512F-NEXT: vpternlogq $15, %zmm2, %zmm2, %zmm2
; AVX512F-NEXT: vpbroadcastq %xmm2, %ymm2
-; AVX512F-NEXT: vpand %ymm3, %ymm0, %ymm0
-; AVX512F-NEXT: vpand %ymm2, %ymm1, %ymm1
+; AVX512F-NEXT: vpand %ymm2, %ymm0, %ymm0
+; AVX512F-NEXT: vpandn %ymm1, %ymm2, %ymm1
; AVX512F-NEXT: vpor %ymm1, %ymm0, %ymm0
; AVX512F-NEXT: retq
%1 = insertelement <4 x i64> undef, i64 %a2, i32 0
@@ -394,27 +388,18 @@ define <4 x i64> @bitselect_v4i64_broadcast_rrm(<4 x i64> %a0, <4 x i64> %a1, i6
;
; AVX2-LABEL: bitselect_v4i64_broadcast_rrm:
; AVX2: # %bb.0:
-; AVX2-NEXT: vmovq {{.*#+}} xmm2 = mem[0],zero
-; AVX2-NEXT: vpbroadcastq %xmm2, %ymm3
-; AVX2-NEXT: vpcmpeqd %xmm4, %xmm4, %xmm4
-; AVX2-NEXT: vpxor %xmm4, %xmm2, %xmm2
-; AVX2-NEXT: vpbroadcastq %xmm2, %ymm2
-; AVX2-NEXT: vpand %ymm3, %ymm0, %ymm0
-; AVX2-NEXT: vpand %ymm2, %ymm1, %ymm1
-; AVX2-NEXT: vpor %ymm1, %ymm0, %ymm0
+; AVX2-NEXT: vbroadcastsd (%rdi), %ymm2
+; AVX2-NEXT: vandps %ymm2, %ymm0, %ymm0
+; AVX2-NEXT: vandnps %ymm1, %ymm2, %ymm1
+; AVX2-NEXT: vorps %ymm1, %ymm0, %ymm0
; AVX2-NEXT: retq
;
; AVX512F-LABEL: bitselect_v4i64_broadcast_rrm:
; AVX512F: # %bb.0:
-; AVX512F-NEXT: movq (%rdi), %rax
-; AVX512F-NEXT: vmovq %rax, %xmm2
-; AVX512F-NEXT: vmovq %rax, %xmm3
-; AVX512F-NEXT: vpbroadcastq %xmm3, %ymm3
-; AVX512F-NEXT: vpternlogq $15, %zmm2, %zmm2, %zmm2
-; AVX512F-NEXT: vpbroadcastq %xmm2, %ymm2
-; AVX512F-NEXT: vpand %ymm3, %ymm0, %ymm0
-; AVX512F-NEXT: vpand %ymm2, %ymm1, %ymm1
-; AVX512F-NEXT: vpor %ymm1, %ymm0, %ymm0
+; AVX512F-NEXT: vbroadcastsd (%rdi), %ymm2
+; AVX512F-NEXT: vandps %ymm2, %ymm0, %ymm0
+; AVX512F-NEXT: vandnps %ymm1, %ymm2, %ymm1
+; AVX512F-NEXT: vorps %ymm1, %ymm0, %ymm0
; AVX512F-NEXT: retq
%a2 = load i64, i64* %p2
%1 = insertelement <4 x i64> undef, i64 %a2, i32 0
More information about the llvm-commits
mailing list