summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp22
-rw-r--r--llvm/test/Transforms/InstCombine/masked_intrinsics.ll18
2 files changed, 39 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index ede5aeb1cd1..753c8fac96a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -773,6 +773,25 @@ static Value *simplifyMaskedLoad(const IntrinsicInst &II,
return nullptr;
}
+static Instruction *simplifyMaskedStore(IntrinsicInst &II, InstCombiner &IC) {
+ auto *ConstMask = dyn_cast<Constant>(II.getArgOperand(3));
+ if (!ConstMask)
+ return nullptr;
+
+ // If the mask is all zeros, this instruction does nothing.
+ if (ConstMask->isNullValue())
+ return IC.EraseInstFromFunction(II);
+
+ // If the mask is all ones, this is a plain vector store of the 1st argument.
+ if (ConstMask->isAllOnesValue()) {
+ Value *StorePtr = II.getArgOperand(1);
+ unsigned Alignment = cast<ConstantInt>(II.getArgOperand(2))->getZExtValue();
+ return new StoreInst(II.getArgOperand(0), StorePtr, false, Alignment);
+ }
+
+ return nullptr;
+}
+
/// CallInst simplification. This mostly only handles folding of intrinsic
/// instructions. For normal calls, it allows visitCallSite to do the heavy
/// lifting.
@@ -901,9 +920,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
if (Value *SimplifiedMaskedOp = simplifyMaskedLoad(*II, *Builder))
return ReplaceInstUsesWith(CI, SimplifiedMaskedOp);
break;
+ case Intrinsic::masked_store:
+ return simplifyMaskedStore(*II, *this);
// TODO: Handle the other masked ops.
- // case Intrinsic::masked_store:
// case Intrinsic::masked_gather:
// case Intrinsic::masked_scatter:
diff --git a/llvm/test/Transforms/InstCombine/masked_intrinsics.ll b/llvm/test/Transforms/InstCombine/masked_intrinsics.ll
index 3289e3d7744..b40c62784aa 100644
--- a/llvm/test/Transforms/InstCombine/masked_intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/masked_intrinsics.ll
@@ -1,6 +1,7 @@
; RUN: opt -instcombine -S < %s | FileCheck %s
declare <2 x double> @llvm.masked.load.v2f64(<2 x double>* %ptrs, i32, <2 x i1> %mask, <2 x double> %src0)
+declare void @llvm.masked.store.v2f64(<2 x double> %val, <2 x double>* %ptrs, i32, <2 x i1> %mask)
define <2 x double> @load_zeromask(<2 x double>* %ptr, <2 x double> %passthru) {
@@ -20,3 +21,20 @@ define <2 x double> @load_onemask(<2 x double>* %ptr, <2 x double> %passthru) {
; CHECK-NEXT: ret <2 x double> %unmaskedload
}
+define void @store_zeromask(<2 x double>* %ptr, <2 x double> %val) {
+ call void @llvm.masked.store.v2f64(<2 x double> %val, <2 x double>* %ptr, i32 3, <2 x i1> zeroinitializer)
+ ret void
+
+; CHECK-LABEL: @store_zeromask(
+; CHECK-NEXT: ret void
+}
+
+define void @store_onemask(<2 x double>* %ptr, <2 x double> %val) {
+ call void @llvm.masked.store.v2f64(<2 x double> %val, <2 x double>* %ptr, i32 4, <2 x i1> <i1 1, i1 1>)
+ ret void
+
+; CHECK-LABEL: @store_onemask(
+; CHECK-NEXT: store <2 x double> %val, <2 x double>* %ptr, align 4
+; CHECK-NEXT: ret void
+}
+
OpenPOWER on IntegriCloud