[PATCH] D132700: Add value type checks for masked store candidates in DSE
Michael Berg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 25 12:53:17 PDT 2022
mcberg2021 created this revision.
mcberg2021 added reviewers: craig.topper, reames.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
mcberg2021 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
The types of the store values can diverge when checking for valid mask store candidates to eliminate via DSE.
https://reviews.llvm.org/D132700
Files:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/masked-dead-store-no-merge.ll
Index: llvm/test/Transforms/DeadStoreElimination/masked-dead-store-no-merge.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/DeadStoreElimination/masked-dead-store-no-merge.ll
@@ -0,0 +1,18 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -tbaa -dse -S < %s | FileCheck %s
+target datalayout = "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048"
+
+define void @foo(ptr %a, <4 x i8> %v1, <4 x i32> %v2) {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT: tail call void @llvm.masked.store.v4i32.p0(<4 x i32> [[V2:%.*]], ptr [[A:%.*]], i32 1, <4 x i1> <i1 true, i1 true, i1 true, i1 true>)
+; CHECK-NEXT: tail call void @llvm.masked.store.v4i8.p0(<4 x i8> [[V1:%.*]], ptr [[A]], i32 1, <4 x i1> <i1 true, i1 true, i1 true, i1 true>)
+; CHECK-NEXT: ret void
+;
+ tail call void @llvm.masked.store.v4i32.p0(<4 x i32> %v2, ptr %a, i32 1, <4 x i1> <i1 true, i1 true, i1 true, i1 true>)
+ tail call void @llvm.masked.store.v4i8.p0(<4 x i8> %v1, ptr %a, i32 1, <4 x i1> <i1 true, i1 true, i1 true, i1 true>)
+ ret void
+}
+
+declare void @llvm.masked.store.v4i8.p0(<4 x i8>, ptr, i32, <4 x i1>)
+declare void @llvm.masked.store.v4i32.p0(<4 x i32>, ptr, i32, <4 x i1>)
+
Index: llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -242,19 +242,26 @@
const auto *DeadII = dyn_cast<IntrinsicInst>(DeadI);
if (KillingII == nullptr || DeadII == nullptr)
return OW_Unknown;
- if (KillingII->getIntrinsicID() != Intrinsic::masked_store ||
- DeadII->getIntrinsicID() != Intrinsic::masked_store)
+ // Only like type intrinsics...
+ if (KillingII->getIntrinsicID() != DeadII->getIntrinsicID())
return OW_Unknown;
- // Pointers.
- Value *KillingPtr = KillingII->getArgOperand(1)->stripPointerCasts();
- Value *DeadPtr = DeadII->getArgOperand(1)->stripPointerCasts();
- if (KillingPtr != DeadPtr && !AA.isMustAlias(KillingPtr, DeadPtr))
- return OW_Unknown;
- // Masks.
- // TODO: check that KillingII's mask is a superset of the DeadII's mask.
- if (KillingII->getArgOperand(3) != DeadII->getArgOperand(3))
- return OW_Unknown;
- return OW_Complete;
+ if (KillingII->getIntrinsicID() == Intrinsic::masked_store) {
+ // Types.
+ if (KillingII->getArgOperand(0)->getType() !=
+ DeadII->getArgOperand(0)->getType())
+ return OW_Unknown;
+ // Pointers.
+ Value *KillingPtr = KillingII->getArgOperand(1)->stripPointerCasts();
+ Value *DeadPtr = DeadII->getArgOperand(1)->stripPointerCasts();
+ if (KillingPtr != DeadPtr && !AA.isMustAlias(KillingPtr, DeadPtr))
+ return OW_Unknown;
+ // Masks.
+ // TODO: check that KillingII's mask is a superset of the DeadII's mask.
+ if (KillingII->getArgOperand(3) != DeadII->getArgOperand(3))
+ return OW_Unknown;
+ return OW_Complete;
+ }
+ return OW_Unknown;
}
/// Return 'OW_Complete' if a store to the 'KillingLoc' location completely
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132700.455690.patch
Type: text/x-patch
Size: 3235 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220825/25deaa28/attachment.bin>
More information about the llvm-commits
mailing list