diff options
author | David Majnemer <david.majnemer@gmail.com> | 2016-07-14 06:58:37 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2016-07-14 06:58:37 +0000 |
commit | 17a95aaa7b63bb7f41be61dc5327c9ea46765c6a (patch) | |
tree | a88f3470c69433de0bba5e755afaefbae784856a /llvm/lib/Analysis/InstructionSimplify.cpp | |
parent | 6840f1150f5c550d62aececfa8e061465574deb6 (diff) | |
download | llvm-17a95aaa7b63bb7f41be61dc5327c9ea46765c6a.zip llvm-17a95aaa7b63bb7f41be61dc5327c9ea46765c6a.tar.gz llvm-17a95aaa7b63bb7f41be61dc5327c9ea46765c6a.tar.bz2 |
Simplify llvm.masked.load w/ undef masks
We can always pick the passthru value if the mask is undef: we are
permitted to treat the mask as-if it were filled with zeros.
llvm-svn: 275379
Diffstat (limited to 'llvm/lib/Analysis/InstructionSimplify.cpp')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 609cd26..0cb2c78 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -3944,6 +3944,22 @@ static Value *SimplifyRelativeLoad(Constant *Ptr, Constant *Offset, return ConstantExpr::getBitCast(LoadedLHSPtr, Int8PtrTy); } +static bool maskIsAllZeroOrUndef(Value *Mask) { + auto *ConstMask = dyn_cast<Constant>(Mask); + if (!ConstMask) + return false; + if (ConstMask->isNullValue() || isa<UndefValue>(ConstMask)) + return true; + for (unsigned I = 0, E = ConstMask->getType()->getVectorNumElements(); I != E; + ++I) { + if (auto *MaskElt = ConstMask->getAggregateElement(I)) + if (MaskElt->isNullValue() || isa<UndefValue>(MaskElt)) + continue; + return false; + } + return true; +} + template <typename IterTy> static Value *SimplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd, const Query &Q, unsigned MaxRecurse) { @@ -3993,11 +4009,11 @@ static Value *SimplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd, // Simplify calls to llvm.masked.load.* if (IID == Intrinsic::masked_load) { - IterTy MaskArg = ArgBegin + 2; - // If the mask is all zeros, the "passthru" argument is the result. - if (auto *ConstMask = dyn_cast<Constant>(*MaskArg)) - if (ConstMask->isNullValue()) - return ArgBegin[3]; + Value *MaskArg = ArgBegin[2]; + Value *PassthruArg = ArgBegin[3]; + // If the mask is all zeros or undef, the "passthru" argument is the result. + if (maskIsAllZeroOrUndef(MaskArg)) + return PassthruArg; } // Perform idempotent optimizations |