summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2016-02-01 22:10:26 +0000
committerSanjay Patel <spatel@rotateright.com>2016-02-01 22:10:26 +0000
commit103ab7d571dbbd531cd78b8f2293b199f16c8c02 (patch)
tree45c926d77c8253e368234af9a09e0586ae57c369 /llvm/lib/Transforms
parent025a3d857a3649dff84f4c3cd02e8e6132b24613 (diff)
downloadbcm5719-llvm-103ab7d571dbbd531cd78b8f2293b199f16c8c02.tar.gz
bcm5719-llvm-103ab7d571dbbd531cd78b8f2293b199f16c8c02.zip
[InstCombine] simplify masked scatter/gather intrinsics with zero masks
A masked scatter with a zero mask means there's no store. A masked gather with a zero mask means the passthru arg is returned. This is a continuation of: http://reviews.llvm.org/rL259369 http://reviews.llvm.org/rL259392 llvm-svn: 259421
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 753c8fac96a..463a6c28666 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -792,6 +792,24 @@ static Instruction *simplifyMaskedStore(IntrinsicInst &II, InstCombiner &IC) {
return nullptr;
}
+static Instruction *simplifyMaskedGather(IntrinsicInst &II, InstCombiner &IC) {
+ // If the mask is all zeros, return the "passthru" argument of the gather.
+ auto *ConstMask = dyn_cast<Constant>(II.getArgOperand(2));
+ if (ConstMask && ConstMask->isNullValue())
+ return IC.ReplaceInstUsesWith(II, II.getArgOperand(3));
+
+ return nullptr;
+}
+
+static Instruction *simplifyMaskedScatter(IntrinsicInst &II, InstCombiner &IC) {
+ // If the mask is all zeros, a scatter does nothing.
+ auto *ConstMask = dyn_cast<Constant>(II.getArgOperand(3));
+ if (ConstMask && ConstMask->isNullValue())
+ return IC.EraseInstFromFunction(II);
+
+ return nullptr;
+}
+
/// CallInst simplification. This mostly only handles folding of intrinsic
/// instructions. For normal calls, it allows visitCallSite to do the heavy
/// lifting.
@@ -922,10 +940,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
break;
case Intrinsic::masked_store:
return simplifyMaskedStore(*II, *this);
-
- // TODO: Handle the other masked ops.
- // case Intrinsic::masked_gather:
- // case Intrinsic::masked_scatter:
+ case Intrinsic::masked_gather:
+ return simplifyMaskedGather(*II, *this);
+ case Intrinsic::masked_scatter:
+ return simplifyMaskedScatter(*II, *this);
case Intrinsic::powi:
if (ConstantInt *Power = dyn_cast<ConstantInt>(II->getArgOperand(1))) {
OpenPOWER on IntegriCloud