1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00

[VPlan] Add & use VPValue operands for VPWidenCallRecipe (NFC).

This patch adds VPValue versions for the arguments of the call to
VPWidenCallRecipe and uses them during code-generation.

Similar to D76373 this reduces ingredient def-use usage by ILV as
a step towards full VPlan-based def-use relations.

Reviewers: Ayal, gilr, rengolin

Reviewed By: gilr

Differential Revision: https://reviews.llvm.org/D77655
This commit is contained in:
Florian Hahn 2020-04-09 10:23:21 +01:00
parent 89d4bb7e9b
commit 3a34bf824e
4 changed files with 34 additions and 13 deletions

View File

@ -410,7 +410,8 @@ public:
void widenInstruction(Instruction &I);
/// Widen a single call instruction within the innermost loop.
void widenCallInstruction(CallInst &I);
void widenCallInstruction(CallInst &I, VPUser &ArgOperands,
VPTransformState &State);
/// Fix the vectorized code, taking care of header phi's, live-outs, and more.
void fixVectorizedLoop();
@ -4359,7 +4360,8 @@ void InnerLoopVectorizer::widenInstruction(Instruction &I) {
} // end of switch.
}
void InnerLoopVectorizer::widenCallInstruction(CallInst &I) {
void InnerLoopVectorizer::widenCallInstruction(CallInst &I, VPUser &ArgOperands,
VPTransformState &State) {
// Ignore dbg intrinsics.
// TODO: Debug intrinsics should be skipped/handled during VPlan construction
// rather than dropping them here.
@ -4388,12 +4390,14 @@ void InnerLoopVectorizer::widenCallInstruction(CallInst &I) {
for (unsigned Part = 0; Part < UF; ++Part) {
SmallVector<Value *, 4> Args;
for (unsigned i = 0, ie = CI->getNumArgOperands(); i != ie; ++i) {
Value *Arg = CI->getArgOperand(i);
for (auto &I : enumerate(ArgOperands.operands())) {
// Some intrinsics have a scalar argument - don't replace it with a
// vector.
if (!UseVectorIntrinsic || !hasVectorInstrinsicScalarOpd(ID, i))
Arg = getOrCreateVectorValue(CI->getArgOperand(i), Part);
Value *Arg;
if (!UseVectorIntrinsic || !hasVectorInstrinsicScalarOpd(ID, I.index()))
Arg = State.get(I.value(), Part);
else
Arg = State.get(I.value(), {0, 0});
Args.push_back(Arg);
}
@ -6887,8 +6891,8 @@ VPBlendRecipe *VPRecipeBuilder::tryToBlend(Instruction *I, VPlanPtr &Plan) {
return new VPBlendRecipe(Phi, Masks);
}
VPWidenCallRecipe *VPRecipeBuilder::tryToWidenCall(Instruction *I,
VFRange &Range) {
VPWidenCallRecipe *
VPRecipeBuilder::tryToWidenCall(Instruction *I, VFRange &Range, VPlan &Plan) {
bool IsPredicated = LoopVectorizationPlanner::getDecisionAndClampRange(
[&](unsigned VF) { return CM.isScalarWithPredication(I, VF); }, Range);
@ -6919,7 +6923,11 @@ VPWidenCallRecipe *VPRecipeBuilder::tryToWidenCall(Instruction *I,
return nullptr;
// Success: widen this call.
return new VPWidenCallRecipe(*CI);
auto VPValues = map_range(CI->arg_operands(), [&Plan](Value *Op) {
return Plan.getOrAddVPValue(Op);
});
return new VPWidenCallRecipe(*CI, VPValues);
}
VPWidenRecipe *VPRecipeBuilder::tryToWiden(Instruction *I, VFRange &Range) {
@ -7071,7 +7079,7 @@ bool VPRecipeBuilder::tryToCreateRecipe(Instruction *Instr, VFRange &Range,
// First, check for specific widening recipes that deal with calls, memory
// operations, inductions and Phi nodes.
if ((Recipe = tryToWidenCall(Instr, Range)) ||
if ((Recipe = tryToWidenCall(Instr, Range, *Plan)) ||
(Recipe = tryToWidenMemory(Instr, Range, Plan)) ||
(Recipe = tryToOptimizeInduction(Instr, Range)) ||
(Recipe = tryToBlend(Instr, Plan)) ||
@ -7390,7 +7398,7 @@ void VPInterleaveRecipe::print(raw_ostream &O, const Twine &Indent,
}
void VPWidenCallRecipe::execute(VPTransformState &State) {
State.ILV->widenCallInstruction(Ingredient);
State.ILV->widenCallInstruction(Ingredient, User, State);
}
void VPWidenRecipe::execute(VPTransformState &State) {

View File

@ -110,7 +110,8 @@ public:
/// Handle call instruction. If \p I is a call that can be widened for \p
/// Range.Start, return a new VPWidenCallRecipe. Range.End may be decreased to
/// ensure same decision from \p Range.Start to \p Range.End.
VPWidenCallRecipe *tryToWidenCall(Instruction *I, VFRange &Range);
VPWidenCallRecipe *tryToWidenCall(Instruction *I, VFRange &Range,
VPlan &Plan);
/// Check if \p I can be widened within the given VF \p Range. If \p I can be
/// widened for \p Range.Start, build a new VPWidenRecipe and return it.

View File

@ -790,8 +790,13 @@ private:
/// Hold the call to be widened.
CallInst &Ingredient;
/// Hold VPValues for the arguments of the call.
VPUser User;
public:
VPWidenCallRecipe(CallInst &I) : VPRecipeBase(VPWidenCallSC), Ingredient(I) {}
template <typename IterT>
VPWidenCallRecipe(CallInst &I, iterator_range<IterT> CallArguments)
: VPRecipeBase(VPWidenCallSC), Ingredient(I), User(CallArguments) {}
~VPWidenCallRecipe() override = default;

View File

@ -22,6 +22,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
@ -147,6 +148,12 @@ public:
VPUser(ArrayRef<VPValue *> Operands) : VPUser(VPValue::VPUserSC, Operands) {}
VPUser(std::initializer_list<VPValue *> Operands)
: VPUser(ArrayRef<VPValue *>(Operands)) {}
template <typename IterT>
VPUser(iterator_range<IterT> Operands) : VPValue(VPValue::VPUserSC) {
for (VPValue *Operand : Operands)
addOperand(Operand);
}
VPUser(const VPUser &) = delete;
VPUser &operator=(const VPUser &) = delete;