diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/CodeGen/ExpandVectorPredication.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/CodeGen/ExpandVectorPredication.cpp | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/contrib/llvm-project/llvm/lib/CodeGen/ExpandVectorPredication.cpp b/contrib/llvm-project/llvm/lib/CodeGen/ExpandVectorPredication.cpp index db4d42bf3ca4..5ee76ff567fb 100644 --- a/contrib/llvm-project/llvm/lib/CodeGen/ExpandVectorPredication.cpp +++ b/contrib/llvm-project/llvm/lib/CodeGen/ExpandVectorPredication.cpp @@ -29,6 +29,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" +#include <optional> using namespace llvm; @@ -122,7 +123,7 @@ static bool maySpeculateLanes(VPIntrinsic &VPI) { if (isa<VPReductionIntrinsic>(VPI)) return false; // Fallback to whether the intrinsic is speculatable. - Optional<unsigned> OpcOpt = VPI.getFunctionalOpcode(); + std::optional<unsigned> OpcOpt = VPI.getFunctionalOpcode(); unsigned FunctionalOpc = OpcOpt.value_or((unsigned)Instruction::Call); return isSafeToSpeculativelyExecuteWithOpcode(FunctionalOpc, &VPI); } @@ -166,25 +167,27 @@ struct CachingVPExpander { /// length of the operation. void discardEVLParameter(VPIntrinsic &PI); - /// \brief Lower this VP binary operator to a unpredicated binary operator. + /// Lower this VP binary operator to a unpredicated binary operator. Value *expandPredicationInBinaryOperator(IRBuilder<> &Builder, VPIntrinsic &PI); - /// \brief Lower this VP reduction to a call to an unpredicated reduction - /// intrinsic. + /// Lower this VP reduction to a call to an unpredicated reduction intrinsic. Value *expandPredicationInReduction(IRBuilder<> &Builder, VPReductionIntrinsic &PI); - /// \brief Lower this VP memory operation to a non-VP intrinsic. + /// Lower this VP memory operation to a non-VP intrinsic. Value *expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder, VPIntrinsic &VPI); - /// \brief Query TTI and expand the vector predication in \p P accordingly. + /// Lower this VP comparison to a call to an unpredicated comparison. + Value *expandPredicationInComparison(IRBuilder<> &Builder, + VPCmpIntrinsic &PI); + + /// Query TTI and expand the vector predication in \p P accordingly. Value *expandPredication(VPIntrinsic &PI); - /// \brief Determine how and whether the VPIntrinsic \p VPI shall be - /// expanded. This overrides TTI with the cl::opts listed at the top of this - /// file. + /// Determine how and whether the VPIntrinsic \p VPI shall be expanded. This + /// overrides TTI with the cl::opts listed at the top of this file. VPLegalization getVPLegalizationStrategy(const VPIntrinsic &VPI) const; bool UsingTTIOverrides; @@ -293,7 +296,7 @@ static Value *getNeutralReductionElement(const VPReductionIntrinsic &VPI, APInt::getSignedMinValue(EltBits)); case Intrinsic::vp_reduce_fmax: Negative = true; - LLVM_FALLTHROUGH; + [[fallthrough]]; case Intrinsic::vp_reduce_fmin: { FastMathFlags Flags = VPI.getFastMathFlags(); const fltSemantics &Semantics = EltTy->getFltSemantics(); @@ -420,7 +423,7 @@ CachingVPExpander::expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder, StoreInst *NewStore = Builder.CreateStore(DataParam, PtrParam, /*IsVolatile*/ false); if (AlignOpt.has_value()) - NewStore->setAlignment(AlignOpt.value()); + NewStore->setAlignment(*AlignOpt); NewMemoryInst = NewStore; } else NewMemoryInst = Builder.CreateMaskedStore( @@ -432,7 +435,7 @@ CachingVPExpander::expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder, LoadInst *NewLoad = Builder.CreateLoad(VPI.getType(), PtrParam, /*IsVolatile*/ false); if (AlignOpt.has_value()) - NewLoad->setAlignment(AlignOpt.value()); + NewLoad->setAlignment(*AlignOpt); NewMemoryInst = NewLoad; } else NewMemoryInst = Builder.CreateMaskedLoad( @@ -462,6 +465,24 @@ CachingVPExpander::expandPredicationInMemoryIntrinsic(IRBuilder<> &Builder, return NewMemoryInst; } +Value *CachingVPExpander::expandPredicationInComparison(IRBuilder<> &Builder, + VPCmpIntrinsic &VPI) { + assert((maySpeculateLanes(VPI) || VPI.canIgnoreVectorLengthParam()) && + "Implicitly dropping %evl in non-speculatable operator!"); + + assert(*VPI.getFunctionalOpcode() == Instruction::ICmp || + *VPI.getFunctionalOpcode() == Instruction::FCmp); + + Value *Op0 = VPI.getOperand(0); + Value *Op1 = VPI.getOperand(1); + auto Pred = VPI.getPredicate(); + + auto *NewCmp = Builder.CreateCmp(Pred, Op0, Op1); + + replaceOperation(*NewCmp, VPI); + return NewCmp; +} + void CachingVPExpander::discardEVLParameter(VPIntrinsic &VPI) { LLVM_DEBUG(dbgs() << "Discard EVL parameter in " << VPI << "\n"); @@ -538,6 +559,9 @@ Value *CachingVPExpander::expandPredication(VPIntrinsic &VPI) { if (auto *VPRI = dyn_cast<VPReductionIntrinsic>(&VPI)) return expandPredicationInReduction(Builder, *VPRI); + if (auto *VPCmp = dyn_cast<VPCmpIntrinsic>(&VPI)) + return expandPredicationInComparison(Builder, *VPCmp); + switch (VPI.getIntrinsicID()) { default: break; @@ -598,7 +622,7 @@ CachingVPExpander::getVPLegalizationStrategy(const VPIntrinsic &VPI) const { return VPStrat; } -/// \brief Expand llvm.vp.* intrinsics as requested by \p TTI. +/// Expand llvm.vp.* intrinsics as requested by \p TTI. bool CachingVPExpander::expandVectorPredication() { SmallVector<TransformJob, 16> Worklist; |