forked from OSchip/llvm-project
[SLPVectorizer] Remove RawInstructionsData/getMainOpcode and merge into getSameOpcode
This is part of the work to cleanup use of 'alternate' ops so we can use the more general SK_Select shuffle type. Only getSameOpcode calls getMainOpcode and much of the logic is repeated in both functions. This will require some reworking of D28907 but that patch has hit trouble and is unlikely to be completed anytime soon. Differential Revision: https://reviews.llvm.org/D48120 llvm-svn: 334701
This commit is contained in:
parent
e6e76fd839
commit
b234ff136e
|
@ -363,40 +363,6 @@ static Value *isOneOf(Value *OpValue, Value *Op) {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
/// Contains data for the instructions going to be vectorized.
|
|
||||||
struct RawInstructionsData {
|
|
||||||
/// Main Opcode of the instructions going to be vectorized.
|
|
||||||
unsigned Opcode = 0;
|
|
||||||
|
|
||||||
/// The list of instructions have some instructions with alternate opcodes.
|
|
||||||
bool HasAltOpcodes = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end anonymous namespace
|
|
||||||
|
|
||||||
/// Checks the list of the vectorized instructions \p VL and returns info about
|
|
||||||
/// this list.
|
|
||||||
static RawInstructionsData getMainOpcode(ArrayRef<Value *> VL) {
|
|
||||||
auto *I0 = dyn_cast<Instruction>(VL[0]);
|
|
||||||
if (!I0)
|
|
||||||
return {};
|
|
||||||
RawInstructionsData Res;
|
|
||||||
unsigned Opcode = I0->getOpcode();
|
|
||||||
// Walk through the list of the vectorized instructions
|
|
||||||
// in order to check its structure described by RawInstructionsData.
|
|
||||||
for (unsigned Cnt = 0, E = VL.size(); Cnt != E; ++Cnt) {
|
|
||||||
auto *I = dyn_cast<Instruction>(VL[Cnt]);
|
|
||||||
if (!I)
|
|
||||||
return {};
|
|
||||||
if (Opcode != I->getOpcode())
|
|
||||||
Res.HasAltOpcodes = true;
|
|
||||||
}
|
|
||||||
Res.Opcode = Opcode;
|
|
||||||
return Res;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
/// Main data required for vectorization of instructions.
|
/// Main data required for vectorization of instructions.
|
||||||
struct InstructionsState {
|
struct InstructionsState {
|
||||||
/// The very first instruction in the list with the main opcode.
|
/// The very first instruction in the list with the main opcode.
|
||||||
|
@ -419,21 +385,26 @@ struct InstructionsState {
|
||||||
/// InstructionsState, the Opcode that we suppose the whole list
|
/// InstructionsState, the Opcode that we suppose the whole list
|
||||||
/// could be vectorized even if its structure is diverse.
|
/// could be vectorized even if its structure is diverse.
|
||||||
static InstructionsState getSameOpcode(ArrayRef<Value *> VL) {
|
static InstructionsState getSameOpcode(ArrayRef<Value *> VL) {
|
||||||
auto Res = getMainOpcode(VL);
|
// Make sure these are all Instructions.
|
||||||
unsigned Opcode = Res.Opcode;
|
if (llvm::any_of(VL, [](Value *V) { return !isa<Instruction>(V); }))
|
||||||
if (!Res.HasAltOpcodes)
|
return InstructionsState(VL[0], 0, false);
|
||||||
return InstructionsState(VL[0], Opcode, false);
|
|
||||||
unsigned AltOpcode = getAltOpcode(Opcode);
|
unsigned Opcode = cast<Instruction>(VL[0])->getOpcode();
|
||||||
// Examine each element in the list instructions VL to determine
|
bool HasAltOpcodes = llvm::any_of(VL, [Opcode](Value *V) {
|
||||||
// if some operations there could be considered as an alternative
|
return Opcode != cast<Instruction>(V)->getOpcode();
|
||||||
// (for example as subtraction relates to addition operation).
|
});
|
||||||
for (int Cnt = 0, E = VL.size(); Cnt < E; Cnt++) {
|
|
||||||
auto *I = cast<Instruction>(VL[Cnt]);
|
// Check for an alternate opcode pattern.
|
||||||
unsigned InstOpcode = I->getOpcode();
|
if (HasAltOpcodes) {
|
||||||
if (InstOpcode != (isOdd(Cnt) ? AltOpcode : Opcode))
|
unsigned AltOpcode = getAltOpcode(Opcode);
|
||||||
return InstructionsState(VL[0], 0, false);
|
for (int Cnt = 0, E = VL.size(); Cnt < E; Cnt++) {
|
||||||
|
unsigned InstOpcode = cast<Instruction>(VL[Cnt])->getOpcode();
|
||||||
|
if (InstOpcode != (isOdd(Cnt) ? AltOpcode : Opcode))
|
||||||
|
return InstructionsState(VL[0], 0, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return InstructionsState(VL[0], Opcode, Res.HasAltOpcodes);
|
|
||||||
|
return InstructionsState(VL[0], Opcode, HasAltOpcodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \returns true if all of the values in \p VL have the same type or false
|
/// \returns true if all of the values in \p VL have the same type or false
|
||||||
|
|
Loading…
Reference in New Issue