mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
BBVectorize: Simplify how input swapping is handled.
Stop propagating the FlipMemInputs variable into the routines that create the replacement instructions. Instead, just flip the arguments of those routines. This allows for some associated cleanup (not all of which is done here). No functionality change is intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167042 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -296,7 +296,7 @@ namespace {
|
|||||||
bool UseCycleCheck);
|
bool UseCycleCheck);
|
||||||
|
|
||||||
Value *getReplacementPointerInput(LLVMContext& Context, Instruction *I,
|
Value *getReplacementPointerInput(LLVMContext& Context, Instruction *I,
|
||||||
Instruction *J, unsigned o, bool FlipMemInputs);
|
Instruction *J, unsigned o);
|
||||||
|
|
||||||
void fillNewShuffleMask(LLVMContext& Context, Instruction *J,
|
void fillNewShuffleMask(LLVMContext& Context, Instruction *J,
|
||||||
unsigned MaskOffset, unsigned NumInElem,
|
unsigned MaskOffset, unsigned NumInElem,
|
||||||
@ -312,16 +312,15 @@ namespace {
|
|||||||
unsigned IdxOff = 0);
|
unsigned IdxOff = 0);
|
||||||
|
|
||||||
Value *getReplacementInput(LLVMContext& Context, Instruction *I,
|
Value *getReplacementInput(LLVMContext& Context, Instruction *I,
|
||||||
Instruction *J, unsigned o, bool FlipMemInputs);
|
Instruction *J, unsigned o);
|
||||||
|
|
||||||
void getReplacementInputsForPair(LLVMContext& Context, Instruction *I,
|
void getReplacementInputsForPair(LLVMContext& Context, Instruction *I,
|
||||||
Instruction *J, SmallVector<Value *, 3> &ReplacedOperands,
|
Instruction *J, SmallVector<Value *, 3> &ReplacedOperands);
|
||||||
bool FlipMemInputs);
|
|
||||||
|
|
||||||
void replaceOutputsOfPair(LLVMContext& Context, Instruction *I,
|
void replaceOutputsOfPair(LLVMContext& Context, Instruction *I,
|
||||||
Instruction *J, Instruction *K,
|
Instruction *J, Instruction *K,
|
||||||
Instruction *&InsertionPt, Instruction *&K1,
|
Instruction *&InsertionPt, Instruction *&K1,
|
||||||
Instruction *&K2, bool FlipMemInputs);
|
Instruction *&K2);
|
||||||
|
|
||||||
void collectPairLoadMoveSet(BasicBlock &BB,
|
void collectPairLoadMoveSet(BasicBlock &BB,
|
||||||
DenseMap<Value *, Value *> &ChosenPairs,
|
DenseMap<Value *, Value *> &ChosenPairs,
|
||||||
@ -1670,25 +1669,19 @@ namespace {
|
|||||||
// Returns the value that is to be used as the pointer input to the vector
|
// Returns the value that is to be used as the pointer input to the vector
|
||||||
// instruction that fuses I with J.
|
// instruction that fuses I with J.
|
||||||
Value *BBVectorize::getReplacementPointerInput(LLVMContext& Context,
|
Value *BBVectorize::getReplacementPointerInput(LLVMContext& Context,
|
||||||
Instruction *I, Instruction *J, unsigned o,
|
Instruction *I, Instruction *J, unsigned o) {
|
||||||
bool FlipMemInputs) {
|
|
||||||
Value *IPtr, *JPtr;
|
Value *IPtr, *JPtr;
|
||||||
unsigned IAlignment, JAlignment, IAddressSpace, JAddressSpace;
|
unsigned IAlignment, JAlignment, IAddressSpace, JAddressSpace;
|
||||||
int64_t OffsetInElmts;
|
int64_t OffsetInElmts;
|
||||||
|
|
||||||
// Note: the analysis might fail here, that is why FlipMemInputs has
|
// Note: the analysis might fail here, that is why the pair order has
|
||||||
// been precomputed (OffsetInElmts must be unused here).
|
// been precomputed (OffsetInElmts must be unused here).
|
||||||
(void) getPairPtrInfo(I, J, IPtr, JPtr, IAlignment, JAlignment,
|
(void) getPairPtrInfo(I, J, IPtr, JPtr, IAlignment, JAlignment,
|
||||||
IAddressSpace, JAddressSpace,
|
IAddressSpace, JAddressSpace,
|
||||||
OffsetInElmts, false);
|
OffsetInElmts, false);
|
||||||
|
|
||||||
// The pointer value is taken to be the one with the lowest offset.
|
// The pointer value is taken to be the one with the lowest offset.
|
||||||
Value *VPtr;
|
Value *VPtr = IPtr;
|
||||||
if (!FlipMemInputs) {
|
|
||||||
VPtr = IPtr;
|
|
||||||
} else {
|
|
||||||
VPtr = JPtr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Type *ArgTypeI = cast<PointerType>(IPtr->getType())->getElementType();
|
Type *ArgTypeI = cast<PointerType>(IPtr->getType())->getElementType();
|
||||||
Type *ArgTypeJ = cast<PointerType>(JPtr->getType())->getElementType();
|
Type *ArgTypeJ = cast<PointerType>(JPtr->getType())->getElementType();
|
||||||
@ -1696,7 +1689,7 @@ namespace {
|
|||||||
Type *VArgPtrType = PointerType::get(VArgType,
|
Type *VArgPtrType = PointerType::get(VArgType,
|
||||||
cast<PointerType>(IPtr->getType())->getAddressSpace());
|
cast<PointerType>(IPtr->getType())->getAddressSpace());
|
||||||
return new BitCastInst(VPtr, VArgPtrType, getReplacementName(I, true, o),
|
return new BitCastInst(VPtr, VArgPtrType, getReplacementName(I, true, o),
|
||||||
/* insert before */ FlipMemInputs ? J : I);
|
/* insert before */ I);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BBVectorize::fillNewShuffleMask(LLVMContext& Context, Instruction *J,
|
void BBVectorize::fillNewShuffleMask(LLVMContext& Context, Instruction *J,
|
||||||
@ -1816,7 +1809,7 @@ namespace {
|
|||||||
// Returns the value to be used as the specified operand of the vector
|
// Returns the value to be used as the specified operand of the vector
|
||||||
// instruction that fuses I with J.
|
// instruction that fuses I with J.
|
||||||
Value *BBVectorize::getReplacementInput(LLVMContext& Context, Instruction *I,
|
Value *BBVectorize::getReplacementInput(LLVMContext& Context, Instruction *I,
|
||||||
Instruction *J, unsigned o, bool FlipMemInputs) {
|
Instruction *J, unsigned o) {
|
||||||
Value *CV0 = ConstantInt::get(Type::getInt32Ty(Context), 0);
|
Value *CV0 = ConstantInt::get(Type::getInt32Ty(Context), 0);
|
||||||
Value *CV1 = ConstantInt::get(Type::getInt32Ty(Context), 1);
|
Value *CV1 = ConstantInt::get(Type::getInt32Ty(Context), 1);
|
||||||
|
|
||||||
@ -1827,12 +1820,6 @@ namespace {
|
|||||||
|
|
||||||
Instruction *L = I, *H = J;
|
Instruction *L = I, *H = J;
|
||||||
Type *ArgTypeL = ArgTypeI, *ArgTypeH = ArgTypeJ;
|
Type *ArgTypeL = ArgTypeI, *ArgTypeH = ArgTypeJ;
|
||||||
if (FlipMemInputs) {
|
|
||||||
L = J;
|
|
||||||
H = I;
|
|
||||||
ArgTypeL = ArgTypeJ;
|
|
||||||
ArgTypeH = ArgTypeI;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned numElemL;
|
unsigned numElemL;
|
||||||
if (ArgTypeL->isVectorTy())
|
if (ArgTypeL->isVectorTy())
|
||||||
@ -2156,8 +2143,7 @@ namespace {
|
|||||||
// to the vector instruction that fuses I with J.
|
// to the vector instruction that fuses I with J.
|
||||||
void BBVectorize::getReplacementInputsForPair(LLVMContext& Context,
|
void BBVectorize::getReplacementInputsForPair(LLVMContext& Context,
|
||||||
Instruction *I, Instruction *J,
|
Instruction *I, Instruction *J,
|
||||||
SmallVector<Value *, 3> &ReplacedOperands,
|
SmallVector<Value *, 3> &ReplacedOperands) {
|
||||||
bool FlipMemInputs) {
|
|
||||||
unsigned NumOperands = I->getNumOperands();
|
unsigned NumOperands = I->getNumOperands();
|
||||||
|
|
||||||
for (unsigned p = 0, o = NumOperands-1; p < NumOperands; ++p, --o) {
|
for (unsigned p = 0, o = NumOperands-1; p < NumOperands; ++p, --o) {
|
||||||
@ -2166,8 +2152,7 @@ namespace {
|
|||||||
|
|
||||||
if (isa<LoadInst>(I) || (o == 1 && isa<StoreInst>(I))) {
|
if (isa<LoadInst>(I) || (o == 1 && isa<StoreInst>(I))) {
|
||||||
// This is the pointer for a load/store instruction.
|
// This is the pointer for a load/store instruction.
|
||||||
ReplacedOperands[o] = getReplacementPointerInput(Context, I, J, o,
|
ReplacedOperands[o] = getReplacementPointerInput(Context, I, J, o);
|
||||||
FlipMemInputs);
|
|
||||||
continue;
|
continue;
|
||||||
} else if (isa<CallInst>(I)) {
|
} else if (isa<CallInst>(I)) {
|
||||||
Function *F = cast<CallInst>(I)->getCalledFunction();
|
Function *F = cast<CallInst>(I)->getCalledFunction();
|
||||||
@ -2195,8 +2180,7 @@ namespace {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReplacedOperands[o] =
|
ReplacedOperands[o] = getReplacementInput(Context, I, J, o);
|
||||||
getReplacementInput(Context, I, J, o, FlipMemInputs);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2207,8 +2191,7 @@ namespace {
|
|||||||
void BBVectorize::replaceOutputsOfPair(LLVMContext& Context, Instruction *I,
|
void BBVectorize::replaceOutputsOfPair(LLVMContext& Context, Instruction *I,
|
||||||
Instruction *J, Instruction *K,
|
Instruction *J, Instruction *K,
|
||||||
Instruction *&InsertionPt,
|
Instruction *&InsertionPt,
|
||||||
Instruction *&K1, Instruction *&K2,
|
Instruction *&K1, Instruction *&K2) {
|
||||||
bool FlipMemInputs) {
|
|
||||||
if (isa<StoreInst>(I)) {
|
if (isa<StoreInst>(I)) {
|
||||||
AA->replaceWithNewValue(I, K);
|
AA->replaceWithNewValue(I, K);
|
||||||
AA->replaceWithNewValue(J, K);
|
AA->replaceWithNewValue(J, K);
|
||||||
@ -2238,13 +2221,11 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
K1 = new ShuffleVectorInst(K, UndefValue::get(VType),
|
K1 = new ShuffleVectorInst(K, UndefValue::get(VType),
|
||||||
ConstantVector::get(
|
ConstantVector::get( Mask1),
|
||||||
FlipMemInputs ? Mask2 : Mask1),
|
|
||||||
getReplacementName(K, false, 1));
|
getReplacementName(K, false, 1));
|
||||||
} else {
|
} else {
|
||||||
Value *CV0 = ConstantInt::get(Type::getInt32Ty(Context), 0);
|
Value *CV0 = ConstantInt::get(Type::getInt32Ty(Context), 0);
|
||||||
Value *CV1 = ConstantInt::get(Type::getInt32Ty(Context), numElem-1);
|
K1 = ExtractElementInst::Create(K, CV0,
|
||||||
K1 = ExtractElementInst::Create(K, FlipMemInputs ? CV1 : CV0,
|
|
||||||
getReplacementName(K, false, 1));
|
getReplacementName(K, false, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2256,13 +2237,11 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
K2 = new ShuffleVectorInst(K, UndefValue::get(VType),
|
K2 = new ShuffleVectorInst(K, UndefValue::get(VType),
|
||||||
ConstantVector::get(
|
ConstantVector::get( Mask2),
|
||||||
FlipMemInputs ? Mask1 : Mask2),
|
|
||||||
getReplacementName(K, false, 2));
|
getReplacementName(K, false, 2));
|
||||||
} else {
|
} else {
|
||||||
Value *CV0 = ConstantInt::get(Type::getInt32Ty(Context), 0);
|
|
||||||
Value *CV1 = ConstantInt::get(Type::getInt32Ty(Context), numElem-1);
|
Value *CV1 = ConstantInt::get(Type::getInt32Ty(Context), numElem-1);
|
||||||
K2 = ExtractElementInst::Create(K, FlipMemInputs ? CV0 : CV1,
|
K2 = ExtractElementInst::Create(K, CV1,
|
||||||
getReplacementName(K, false, 2));
|
getReplacementName(K, false, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2490,10 +2469,14 @@ namespace {
|
|||||||
if (isa<LoadInst>(I) || isa<StoreInst>(I))
|
if (isa<LoadInst>(I) || isa<StoreInst>(I))
|
||||||
FlipMemInputs = (LowPtrInsts.find(I) == LowPtrInsts.end());
|
FlipMemInputs = (LowPtrInsts.find(I) == LowPtrInsts.end());
|
||||||
|
|
||||||
|
Instruction *L = I, *H = J;
|
||||||
|
if (FlipMemInputs)
|
||||||
|
std::swap(H, L);
|
||||||
|
FlipMemInputs = false;
|
||||||
|
|
||||||
unsigned NumOperands = I->getNumOperands();
|
unsigned NumOperands = I->getNumOperands();
|
||||||
SmallVector<Value *, 3> ReplacedOperands(NumOperands);
|
SmallVector<Value *, 3> ReplacedOperands(NumOperands);
|
||||||
getReplacementInputsForPair(Context, I, J, ReplacedOperands,
|
getReplacementInputsForPair(Context, L, H, ReplacedOperands);
|
||||||
FlipMemInputs);
|
|
||||||
|
|
||||||
// Make a copy of the original operation, change its type to the vector
|
// Make a copy of the original operation, change its type to the vector
|
||||||
// type and replace its operands with the vector operands.
|
// type and replace its operands with the vector operands.
|
||||||
@ -2501,7 +2484,7 @@ namespace {
|
|||||||
if (I->hasName()) K->takeName(I);
|
if (I->hasName()) K->takeName(I);
|
||||||
|
|
||||||
if (!isa<StoreInst>(K))
|
if (!isa<StoreInst>(K))
|
||||||
K->mutateType(getVecTypeForPair(I->getType(), J->getType()));
|
K->mutateType(getVecTypeForPair(L->getType(), H->getType()));
|
||||||
|
|
||||||
combineMetadata(K, J);
|
combineMetadata(K, J);
|
||||||
|
|
||||||
@ -2522,8 +2505,7 @@ namespace {
|
|||||||
// Instruction insertion point:
|
// Instruction insertion point:
|
||||||
Instruction *InsertionPt = K;
|
Instruction *InsertionPt = K;
|
||||||
Instruction *K1 = 0, *K2 = 0;
|
Instruction *K1 = 0, *K2 = 0;
|
||||||
replaceOutputsOfPair(Context, I, J, K, InsertionPt, K1, K2,
|
replaceOutputsOfPair(Context, L, H, K, InsertionPt, K1, K2);
|
||||||
FlipMemInputs);
|
|
||||||
|
|
||||||
// The use tree of the first original instruction must be moved to after
|
// The use tree of the first original instruction must be moved to after
|
||||||
// the location of the second instruction. The entire use tree of the
|
// the location of the second instruction. The entire use tree of the
|
||||||
|
Reference in New Issue
Block a user