[llvm] r259392 - [InstCombine] simplify masked store intrinsics with all ones or zeros masks
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 1 11:39:52 PST 2016
Author: spatel
Date: Mon Feb 1 13:39:52 2016
New Revision: 259392
URL: http://llvm.org/viewvc/llvm-project?rev=259392&view=rev
Log:
[InstCombine] simplify masked store intrinsics with all ones or zeros masks
A masked store with a zero mask means there's no store.
A masked store with an allOnes mask means it's a normal vector store.
This is a continuation of:
http://reviews.llvm.org/rL259369
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/test/Transforms/InstCombine/masked_intrinsics.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=259392&r1=259391&r2=259392&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Mon Feb 1 13:39:52 2016
@@ -773,6 +773,25 @@ static Value *simplifyMaskedLoad(const I
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
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:
Modified: llvm/trunk/test/Transforms/InstCombine/masked_intrinsics.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/masked_intrinsics.ll?rev=259392&r1=259391&r2=259392&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/masked_intrinsics.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/masked_intrinsics.ll Mon Feb 1 13:39:52 2016
@@ -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 d
; 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
+}
+
More information about the llvm-commits
mailing list