[llvm] 897a79f - [DSE] Add value type info checks for masked store candidates in Dead Store Elimination.
Michael Berg via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 20 15:54:49 PDT 2022
Author: Michael Berg
Date: 2022-09-20T15:54:25-07:00
New Revision: 897a79f97004d377542e4c074cdd696c96c73e2d
URL: https://github.com/llvm/llvm-project/commit/897a79f97004d377542e4c074cdd696c96c73e2d
DIFF: https://github.com/llvm/llvm-project/commit/897a79f97004d377542e4c074cdd696c96c73e2d.diff
LOG: [DSE] Add value type info checks for masked store candidates in Dead Store Elimination.
The type information of the store values can diverge when checking for valid
mask store candidates to eliminate via DSE. This patch checks for equivalence
wrt to size and element count.
Reviewed By: fhahn, rui.zhang
Differential Revision: https://reviews.llvm.org/D132700
Added:
Modified:
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/masked-dead-store.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
index 45c404a140af3..1ed52cce8c208 100644
--- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
@@ -242,19 +242,30 @@ static OverwriteResult isMaskedStoreOverwrite(const Instruction *KillingI,
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)
+ 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) {
+ // Type size.
+ VectorType *KillingTy =
+ cast<VectorType>(KillingII->getArgOperand(0)->getType());
+ VectorType *DeadTy = cast<VectorType>(DeadII->getArgOperand(0)->getType());
+ if (KillingTy->getScalarSizeInBits() != DeadTy->getScalarSizeInBits())
+ return OW_Unknown;
+ // Element count.
+ if (KillingTy->getElementCount() != DeadTy->getElementCount())
+ 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
diff --git a/llvm/test/Transforms/DeadStoreElimination/masked-dead-store.ll b/llvm/test/Transforms/DeadStoreElimination/masked-dead-store.ll
index 9c7eea5a3ab53..5830d45d01b94 100644
--- a/llvm/test/Transforms/DeadStoreElimination/masked-dead-store.ll
+++ b/llvm/test/Transforms/DeadStoreElimination/masked-dead-store.ll
@@ -59,7 +59,8 @@ b0:
define dllexport i32 @f1(<4 x i32>* %a, <4 x i8> %v1, <4 x i32> %v2) {
; CHECK-LABEL: @f1(
-; CHECK-NEXT: [[PTR:%.*]] = bitcast <4 x i32>* [[A:%.*]] to <4 x i8>*
+; CHECK-NEXT: call void @llvm.masked.store.v4i32.p0v4i32(<4 x i32> [[V2:%.*]], <4 x i32>* [[A:%.*]], i32 1, <4 x i1> <i1 true, i1 true, i1 true, i1 true>)
+; CHECK-NEXT: [[PTR:%.*]] = bitcast <4 x i32>* [[A]] to <4 x i8>*
; CHECK-NEXT: call void @llvm.masked.store.v4i8.p0v4i8(<4 x i8> [[V1:%.*]], <4 x i8>* [[PTR]], i32 1, <4 x i1> <i1 true, i1 true, i1 true, i1 true>)
; CHECK-NEXT: ret i32 0
;
@@ -69,6 +70,19 @@ define dllexport i32 @f1(<4 x i32>* %a, <4 x i8> %v1, <4 x i32> %v2) {
ret i32 0
}
+define dllexport i32 @f2(<4 x i32>* %a, <4 x i8> %v1, <4 x i32> %v2, <4 x i1> %mask) {
+; CHECK-LABEL: @f2(
+; CHECK-NEXT: call void @llvm.masked.store.v4i32.p0v4i32(<4 x i32> [[V2:%.*]], <4 x i32>* [[A:%.*]], i32 1, <4 x i1> [[MASK:%.*]])
+; CHECK-NEXT: [[PTR:%.*]] = bitcast <4 x i32>* [[A]] to <4 x i8>*
+; CHECK-NEXT: call void @llvm.masked.store.v4i8.p0v4i8(<4 x i8> [[V1:%.*]], <4 x i8>* [[PTR]], i32 1, <4 x i1> [[MASK]])
+; CHECK-NEXT: ret i32 0
+;
+ tail call void @llvm.masked.store.v4i32.p0(<4 x i32> %v2, <4 x i32>* %a, i32 1, <4 x i1> %mask)
+ %ptr = bitcast <4 x i32>* %a to <4 x i8>*
+ tail call void @llvm.masked.store.v4i8.p0(<4 x i8> %v1, <4 x i8>* %ptr, i32 1, <4 x i1> %mask)
+ ret i32 0
+}
+
declare void @llvm.masked.store.v4i8.p0(<4 x i8>, <4 x i8>*, i32, <4 x i1>)
declare void @llvm.masked.store.v4i32.p0(<4 x i32>, <4 x i32>*, i32, <4 x i1>)
More information about the llvm-commits
mailing list