[llvm] r362015 - [DAGCombiner] Replace gathers with a zero mask with the passthru value
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Wed May 29 12:24:19 PDT 2019
Author: d0k
Date: Wed May 29 12:24:19 2019
New Revision: 362015
URL: http://llvm.org/viewvc/llvm-project?rev=362015&view=rev
Log:
[DAGCombiner] Replace gathers with a zero mask with the passthru value
These can be created by the legalizer when splitting a larger gather.
See https://llvm.org/PR42055 for a motivating example.
Differential Revision: https://reviews.llvm.org/D62613
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/trunk/test/CodeGen/X86/avx2-masked-gather.ll
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=362015&r1=362014&r2=362015&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Wed May 29 12:24:19 2019
@@ -8084,13 +8084,17 @@ SDValue DAGCombiner::visitMSTORE(SDNode
}
SDValue DAGCombiner::visitMGATHER(SDNode *N) {
- if (Level >= AfterLegalizeTypes)
- return SDValue();
-
MaskedGatherSDNode *MGT = cast<MaskedGatherSDNode>(N);
SDValue Mask = MGT->getMask();
SDLoc DL(N);
+ // Zap gathers with a zero mask.
+ if (ISD::isBuildVectorAllZeros(Mask.getNode()))
+ return CombineTo(N, MGT->getPassThru(), MGT->getChain());
+
+ if (Level >= AfterLegalizeTypes)
+ return SDValue();
+
// If the MGATHER result requires splitting and the mask is provided by a
// SETCC, then split both nodes and its operands before legalization. This
// prevents the type legalizer from unrolling SETCC into scalar comparisons
Modified: llvm/trunk/test/CodeGen/X86/avx2-masked-gather.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/avx2-masked-gather.ll?rev=362015&r1=362014&r2=362015&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/avx2-masked-gather.ll (original)
+++ llvm/trunk/test/CodeGen/X86/avx2-masked-gather.ll Wed May 29 12:24:19 2019
@@ -769,3 +769,24 @@ entry:
ret <2 x double> %res
}
+
+define <2 x double> @masked_gather_zeromask(<2 x double*>* %ptr, <2 x double> %dummy, <2 x double> %passthru) {
+; X86-LABEL: masked_gather_zeromask:
+; X86: # %bb.0: # %entry
+; X86-NEXT: vmovaps %xmm1, %xmm0
+; X86-NEXT: retl
+;
+; X64-LABEL: masked_gather_zeromask:
+; X64: # %bb.0: # %entry
+; X64-NEXT: vmovaps %xmm1, %xmm0
+; X64-NEXT: retq
+;
+; NOGATHER-LABEL: masked_gather_zeromask:
+; NOGATHER: # %bb.0: # %entry
+; NOGATHER-NEXT: vmovaps %xmm1, %xmm0
+; NOGATHER-NEXT: retq
+entry:
+ %ld = load <2 x double*>, <2 x double*>* %ptr
+ %res = call <2 x double> @llvm.masked.gather.v2double(<2 x double*> %ld, i32 0, <2 x i1> zeroinitializer, <2 x double> %passthru)
+ ret <2 x double> %res
+}
More information about the llvm-commits
mailing list