diff options
author | Anna Thomas <anna@azul.com> | 2023-06-13 14:41:23 -0400 |
---|---|---|
committer | Anna Thomas <anna@azul.com> | 2023-06-20 13:17:28 -0400 |
commit | ec146cb7c0b4a162ee73463e6c7bb306b99e013b (patch) | |
tree | e8dcfbe139d193d6d894836186bc9bca73240bac /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | 0cb977dda1809182786ad7f8fb14a9af08d37918 (diff) | |
download | llvm-ec146cb7c0b4a162ee73463e6c7bb306b99e013b.zip llvm-ec146cb7c0b4a162ee73463e6c7bb306b99e013b.tar.gz llvm-ec146cb7c0b4a162ee73463e6c7bb306b99e013b.tar.bz2 |
[LV] Add support for minimum/maximum intrinsics
{mini|maxi}mum intrinsics are different from {min|max}num intrinsics in
the propagation of NaN and signed zero. Also, the minnum/maxnum
intrinsics require the presence of nsz flags to be valid reductions in
vectorizer. In this regard, we introduce a new recurrence kind and also
add support for identifying reduction patterns using these intrinsics.
The reduction intrinsics and lowering was introduced here: 26bfbec5d2.
There are tests added which show how this interacts across chains of
min/max patterns.
Differential Revision: https://reviews.llvm.org/D151482
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index 90c9396..2dfaea7 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -909,6 +909,10 @@ Intrinsic::ID llvm::getMinMaxReductionIntrinsicOp(RecurKind RK) { return Intrinsic::minnum; case RecurKind::FMax: return Intrinsic::maxnum; + case RecurKind::FMinimum: + return Intrinsic::minimum; + case RecurKind::FMaximum: + return Intrinsic::maximum; } } @@ -928,6 +932,9 @@ CmpInst::Predicate llvm::getMinMaxReductionPredicate(RecurKind RK) { return CmpInst::FCMP_OLT; case RecurKind::FMax: return CmpInst::FCMP_OGT; + // We do not add FMinimum/FMaximum recurrence kind here since there is no + // equivalent predicate which compares signed zeroes according to the + // semantics of the intrinsics (llvm.minimum/maximum). } } @@ -943,7 +950,8 @@ Value *llvm::createSelectCmpOp(IRBuilderBase &Builder, Value *StartVal, Value *llvm::createMinMaxOp(IRBuilderBase &Builder, RecurKind RK, Value *Left, Value *Right) { Type *Ty = Left->getType(); - if (Ty->isIntOrIntVectorTy()) { + if (Ty->isIntOrIntVectorTy() || + (RK == RecurKind::FMinimum || RK == RecurKind::FMaximum)) { // TODO: Add float minnum/maxnum support when FMF nnan is set. Intrinsic::ID Id = getMinMaxReductionIntrinsicOp(RK); return Builder.CreateIntrinsic(Ty, Id, {Left, Right}, nullptr, @@ -1094,6 +1102,10 @@ Value *llvm::createSimpleTargetReduction(IRBuilderBase &Builder, return Builder.CreateFPMaxReduce(Src); case RecurKind::FMin: return Builder.CreateFPMinReduce(Src); + case RecurKind::FMinimum: + return Builder.CreateFPMinimumReduce(Src); + case RecurKind::FMaximum: + return Builder.CreateFPMaximumReduce(Src); default: llvm_unreachable("Unhandled opcode"); } |