diff options
author | Sanjay Patel <spatel@rotateright.com> | 2020-12-30 15:22:26 -0500 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2020-12-30 15:22:26 -0500 |
commit | 8ca60db40bd944dc5f67e0f200a403b4e03818ea (patch) | |
tree | f3cd714c9604b46e9b7666f548157d7ce1e65ce2 /llvm/lib/Transforms/Utils/LoopUtils.cpp | |
parent | 5ced712e9851f00ecd81ba4dc235811bbc9ec5a2 (diff) | |
download | llvm-8ca60db40bd944dc5f67e0f200a403b4e03818ea.zip llvm-8ca60db40bd944dc5f67e0f200a403b4e03818ea.tar.gz llvm-8ca60db40bd944dc5f67e0f200a403b4e03818ea.tar.bz2 |
[LoopUtils] reduce FMF and min/max complexity when forming reductions
I don't know if there's some way this changes what the vectorizers
may produce for reductions, but I have added test coverage with
3567908 and 5ced712 to show that both passes already have bugs in
this area. Hopefully this does not make things worse before we can
really fix it.
Diffstat (limited to 'llvm/lib/Transforms/Utils/LoopUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/LoopUtils.cpp | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index a3665a5..8dc7709 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -985,14 +985,12 @@ llvm::getShuffleReduction(IRBuilderBase &Builder, Value *Src, unsigned Op, /// flags (if generating min/max reductions). Value *llvm::createSimpleTargetReduction( IRBuilderBase &Builder, const TargetTransformInfo *TTI, unsigned Opcode, - Value *Src, TargetTransformInfo::ReductionFlags Flags, + Value *Src, RecurrenceDescriptor::MinMaxRecurrenceKind MinMaxKind, ArrayRef<Value *> RedOps) { auto *SrcVTy = cast<VectorType>(Src->getType()); std::function<Value *()> BuildFunc; using RD = RecurrenceDescriptor; - RD::MinMaxRecurrenceKind MinMaxKind = RD::MRK_Invalid; - switch (Opcode) { case Instruction::Add: BuildFunc = [&]() { return Builder.CreateAddReduce(Src); }; @@ -1024,33 +1022,42 @@ Value *llvm::createSimpleTargetReduction( }; break; case Instruction::ICmp: - if (Flags.IsMaxOp) { - MinMaxKind = Flags.IsSigned ? RD::MRK_SIntMax : RD::MRK_UIntMax; - BuildFunc = [&]() { - return Builder.CreateIntMaxReduce(Src, Flags.IsSigned); - }; - } else { - MinMaxKind = Flags.IsSigned ? RD::MRK_SIntMin : RD::MRK_UIntMin; - BuildFunc = [&]() { - return Builder.CreateIntMinReduce(Src, Flags.IsSigned); - }; + switch (MinMaxKind) { + case RD::MRK_SIntMax: + BuildFunc = [&]() { return Builder.CreateIntMaxReduce(Src, true); }; + break; + case RD::MRK_SIntMin: + BuildFunc = [&]() { return Builder.CreateIntMinReduce(Src, true); }; + break; + case RD::MRK_UIntMax: + BuildFunc = [&]() { return Builder.CreateIntMaxReduce(Src, false); }; + break; + case RD::MRK_UIntMin: + BuildFunc = [&]() { return Builder.CreateIntMinReduce(Src, false); }; + break; + default: + llvm_unreachable("Unexpected min/max reduction type"); } break; case Instruction::FCmp: - if (Flags.IsMaxOp) { - MinMaxKind = RD::MRK_FloatMax; + assert((MinMaxKind == RD::MRK_FloatMax || MinMaxKind == RD::MRK_FloatMin) && + "Unexpected min/max reduction type"); + if (MinMaxKind == RD::MRK_FloatMax) BuildFunc = [&]() { return Builder.CreateFPMaxReduce(Src); }; - } else { - MinMaxKind = RD::MRK_FloatMin; + else BuildFunc = [&]() { return Builder.CreateFPMinReduce(Src); }; - } break; default: llvm_unreachable("Unhandled opcode"); - break; } + TargetTransformInfo::ReductionFlags RdxFlags; + RdxFlags.IsMaxOp = MinMaxKind == RD::MRK_SIntMax || + MinMaxKind == RD::MRK_UIntMax || + MinMaxKind == RD::MRK_FloatMax; + RdxFlags.IsSigned = + MinMaxKind == RD::MRK_SIntMax || MinMaxKind == RD::MRK_SIntMin; if (ForceReductionIntrinsic || - TTI->useReductionIntrinsic(Opcode, Src->getType(), Flags)) + TTI->useReductionIntrinsic(Opcode, Src->getType(), RdxFlags)) return BuildFunc(); return getShuffleReduction(Builder, Src, Opcode, MinMaxKind, RedOps); } @@ -1058,12 +1065,9 @@ Value *llvm::createSimpleTargetReduction( /// Create a vector reduction using a given recurrence descriptor. Value *llvm::createTargetReduction(IRBuilderBase &B, const TargetTransformInfo *TTI, - RecurrenceDescriptor &Desc, Value *Src, - bool NoNaN) { + RecurrenceDescriptor &Desc, Value *Src) { // TODO: Support in-order reductions based on the recurrence descriptor. using RD = RecurrenceDescriptor; - TargetTransformInfo::ReductionFlags Flags; - Flags.NoNaN = NoNaN; // All ops in the reduction inherit fast-math-flags from the recurrence // descriptor. @@ -1071,11 +1075,8 @@ Value *llvm::createTargetReduction(IRBuilderBase &B, B.setFastMathFlags(Desc.getFastMathFlags()); RD::MinMaxRecurrenceKind MMKind = Desc.getMinMaxRecurrenceKind(); - Flags.IsMaxOp = MMKind == RD::MRK_SIntMax || MMKind == RD::MRK_UIntMax || - MMKind == RD::MRK_FloatMax; - Flags.IsSigned = MMKind == RD::MRK_SIntMax || MMKind == RD::MRK_SIntMin; return createSimpleTargetReduction(B, TTI, Desc.getRecurrenceBinOp(), Src, - Flags); + MMKind); } void llvm::propagateIRFlags(Value *I, ArrayRef<Value *> VL, Value *OpValue) { |