[PATCH] D143069: [DAGCombine] Allow DAGCombine to remove dead masked stores
Dinar Temirbulatov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 1 07:01:56 PST 2023
dtemirbulatov created this revision.
dtemirbulatov added reviewers: sdesmalen, david-arm, peterwaller-arm, MattDevereau, RKSimon.
Herald added subscribers: ecnelises, pengfei, hiraditya.
Herald added a project: All.
dtemirbulatov requested review of this revision.
Herald added a project: LLVM.
Remove a dead masked store if another one has the same base pointer and mask.
https://reviews.llvm.org/D143069
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AArch64/sve-dead-masked-store.ll
llvm/test/CodeGen/X86/masked_store.ll
Index: llvm/test/CodeGen/AArch64/sve-dead-masked-store.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sve-dead-masked-store.ll
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=aarch64--linux-gnu -mattr=+sve < %s | FileCheck %s
+
+define void @dead_masked_store(<vscale x 4 x i32> %val, ptr %a, <vscale x 4 x i1> %mask) nounwind {
+; CHECK-LABEL: dead_masked_store:
+; CHECK: // %bb.0:
+; CHECK-NEXT: st1w { z0.s }, p0, [x0]
+; CHECK-NEXT: ret
+ call void @llvm.masked.store.nxv4i32(<vscale x 4 x i32> %val, ptr %a, i32 4, <vscale x 4 x i1> %mask)
+ call void @llvm.masked.store.nxv4i32(<vscale x 4 x i32> %val, ptr %a, i32 4, <vscale x 4 x i1> %mask)
+ ret void
+}
+declare void @llvm.masked.store.nxv4i32(<vscale x 4 x i32>, <vscale x 4 x i32>*, i32, <vscale x 4 x i1>)
Index: llvm/test/CodeGen/X86/masked_store.ll
===================================================================
--- llvm/test/CodeGen/X86/masked_store.ll
+++ llvm/test/CodeGen/X86/masked_store.ll
@@ -5564,7 +5564,6 @@
;
; AVX1OR2-LABEL: PR11210:
; AVX1OR2: ## %bb.0:
-; AVX1OR2-NEXT: vmaskmovps %xmm0, %xmm2, (%rdi)
; AVX1OR2-NEXT: vmaskmovps %xmm1, %xmm2, (%rdi)
; AVX1OR2-NEXT: retq
;
@@ -5572,12 +5571,10 @@
; AVX512F: ## %bb.0:
; AVX512F-NEXT: ## kill: def $xmm2 killed $xmm2 def $zmm2
; AVX512F-NEXT: ## kill: def $xmm1 killed $xmm1 def $zmm1
-; AVX512F-NEXT: ## kill: def $xmm0 killed $xmm0 def $zmm0
-; AVX512F-NEXT: vpxor %xmm3, %xmm3, %xmm3
-; AVX512F-NEXT: vpcmpgtd %zmm2, %zmm3, %k0
+; AVX512F-NEXT: vpxor %xmm0, %xmm0, %xmm0
+; AVX512F-NEXT: vpcmpgtd %zmm2, %zmm0, %k0
; AVX512F-NEXT: kshiftlw $12, %k0, %k0
; AVX512F-NEXT: kshiftrw $12, %k0, %k1
-; AVX512F-NEXT: vmovups %zmm0, (%rdi) {%k1}
; AVX512F-NEXT: vmovups %zmm1, (%rdi) {%k1}
; AVX512F-NEXT: vzeroupper
; AVX512F-NEXT: retq
@@ -5585,15 +5582,13 @@
; AVX512VLDQ-LABEL: PR11210:
; AVX512VLDQ: ## %bb.0:
; AVX512VLDQ-NEXT: vpmovd2m %xmm2, %k1
-; AVX512VLDQ-NEXT: vmovups %xmm0, (%rdi) {%k1}
; AVX512VLDQ-NEXT: vmovups %xmm1, (%rdi) {%k1}
; AVX512VLDQ-NEXT: retq
;
; AVX512VLBW-LABEL: PR11210:
; AVX512VLBW: ## %bb.0:
-; AVX512VLBW-NEXT: vpxor %xmm3, %xmm3, %xmm3
-; AVX512VLBW-NEXT: vpcmpgtd %xmm2, %xmm3, %k1
-; AVX512VLBW-NEXT: vmovups %xmm0, (%rdi) {%k1}
+; AVX512VLBW-NEXT: vpxor %xmm0, %xmm0, %xmm0
+; AVX512VLBW-NEXT: vpcmpgtd %xmm2, %xmm0, %k1
; AVX512VLBW-NEXT: vmovups %xmm1, (%rdi) {%k1}
; AVX512VLBW-NEXT: retq
;
@@ -5601,7 +5596,6 @@
; X86-AVX512: ## %bb.0:
; X86-AVX512-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-AVX512-NEXT: vpmovd2m %xmm2, %k1
-; X86-AVX512-NEXT: vmovups %xmm0, (%eax) {%k1}
; X86-AVX512-NEXT: vmovups %xmm1, (%eax) {%k1}
; X86-AVX512-NEXT: retl
%bc = bitcast <2 x i64> %mask to <4 x i32>
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -11161,6 +11161,23 @@
/*IsTruncating=*/true);
}
+ // Remove a masked store if base pointers and masks are equal.
+ if (MaskedStoreSDNode *MST1 = dyn_cast<MaskedStoreSDNode>(Chain)) {
+ if (MST->isUnindexed() && MST->isSimple() && MST1->isUnindexed() &&
+ MST1->isSimple() && OptLevel != CodeGenOpt::None &&
+ MST1->getBasePtr() == Ptr && MST1->hasOneUse() &&
+ !MST1->getBasePtr().isUndef() &&
+ MST->getAddressSpace() == MST1->getAddressSpace() &&
+ Mask == MST1->getMask() &&
+ TypeSize::isKnownLE(MST1->getMemoryVT().getStoreSize(),
+ MST->getMemoryVT().getStoreSize())) {
+ CombineTo(MST1, MST1->getChain());
+ if (N->getOpcode() != ISD::DELETED_NODE)
+ AddToWorklist(N);
+ return SDValue(N, 0);
+ }
+ }
+
return SDValue();
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143069.493933.patch
Type: text/x-patch
Size: 4065 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230201/0d0ec979/attachment.bin>
More information about the llvm-commits
mailing list