forked from OSchip/llvm-project
Use getStoreSize() in various places instead of 'BitSize >> 3'.
This is needed for cases when the memory access is not as big as the width of the data type. For instance, storing i1 (1 bit) would be done in a byte (8 bits). Using 'BitSize >> 3' (or '/ 8') would e.g. give the memory access of an i1 a size of 0, which for instance makes alias analysis return NoAlias even when it shouldn't. There are no tests as this was done as a follow-up to the bugfix for the case where this was discovered (r318824). This handles more similar cases. Review: Björn Petterson https://reviews.llvm.org/D40339 llvm-svn: 319173
This commit is contained in:
parent
b843dc26e4
commit
f0ff20f1f0
|
@ -848,7 +848,7 @@ bool IRTranslator::translateCall(const User &U, MachineIRBuilder &MIRBuilder) {
|
||||||
Info.vol ? MachineMemOperand::MOVolatile : MachineMemOperand::MONone;
|
Info.vol ? MachineMemOperand::MOVolatile : MachineMemOperand::MONone;
|
||||||
Flags |=
|
Flags |=
|
||||||
Info.readMem ? MachineMemOperand::MOLoad : MachineMemOperand::MOStore;
|
Info.readMem ? MachineMemOperand::MOLoad : MachineMemOperand::MOStore;
|
||||||
uint64_t Size = Info.memVT.getSizeInBits() >> 3;
|
uint64_t Size = Info.memVT.getStoreSize();
|
||||||
MIB.addMemOperand(MF->getMachineMemOperand(MachinePointerInfo(Info.ptrVal),
|
MIB.addMemOperand(MF->getMachineMemOperand(MachinePointerInfo(Info.ptrVal),
|
||||||
Flags, Size, Info.align));
|
Flags, Size, Info.align));
|
||||||
}
|
}
|
||||||
|
|
|
@ -8638,7 +8638,7 @@ SDValue DAGCombiner::CombineConsecutiveLoads(SDNode *N, EVT VT) {
|
||||||
LD1->getAddressSpace() != LD2->getAddressSpace())
|
LD1->getAddressSpace() != LD2->getAddressSpace())
|
||||||
return SDValue();
|
return SDValue();
|
||||||
EVT LD1VT = LD1->getValueType(0);
|
EVT LD1VT = LD1->getValueType(0);
|
||||||
unsigned LD1Bytes = LD1VT.getSizeInBits() / 8;
|
unsigned LD1Bytes = LD1VT.getStoreSize();
|
||||||
if (ISD::isNON_EXTLoad(LD2) && LD2->hasOneUse() &&
|
if (ISD::isNON_EXTLoad(LD2) && LD2->hasOneUse() &&
|
||||||
DAG.areNonVolatileConsecutiveLoads(LD2, LD1, LD1Bytes, 1)) {
|
DAG.areNonVolatileConsecutiveLoads(LD2, LD1, LD1Bytes, 1)) {
|
||||||
unsigned Align = LD1->getAlignment();
|
unsigned Align = LD1->getAlignment();
|
||||||
|
@ -12621,8 +12621,8 @@ bool DAGCombiner::MergeStoresOfConstantsOrVecElts(
|
||||||
// The latest Node in the DAG.
|
// The latest Node in the DAG.
|
||||||
SDLoc DL(StoreNodes[0].MemNode);
|
SDLoc DL(StoreNodes[0].MemNode);
|
||||||
|
|
||||||
int64_t ElementSizeBytes = MemVT.getSizeInBits() / 8;
|
int64_t ElementSizeBits = MemVT.getStoreSizeInBits();
|
||||||
unsigned SizeInBits = NumStores * ElementSizeBytes * 8;
|
unsigned SizeInBits = NumStores * ElementSizeBits;
|
||||||
unsigned NumMemElts = MemVT.isVector() ? MemVT.getVectorNumElements() : 1;
|
unsigned NumMemElts = MemVT.isVector() ? MemVT.getVectorNumElements() : 1;
|
||||||
|
|
||||||
EVT StoreTy;
|
EVT StoreTy;
|
||||||
|
@ -12644,17 +12644,17 @@ bool DAGCombiner::MergeStoresOfConstantsOrVecElts(
|
||||||
if (MemVT != Val.getValueType()) {
|
if (MemVT != Val.getValueType()) {
|
||||||
Val = peekThroughBitcast(Val);
|
Val = peekThroughBitcast(Val);
|
||||||
// Deal with constants of wrong size.
|
// Deal with constants of wrong size.
|
||||||
if (ElementSizeBytes * 8 != Val.getValueSizeInBits()) {
|
if (ElementSizeBits != Val.getValueSizeInBits()) {
|
||||||
EVT IntMemVT =
|
EVT IntMemVT =
|
||||||
EVT::getIntegerVT(*DAG.getContext(), MemVT.getSizeInBits());
|
EVT::getIntegerVT(*DAG.getContext(), MemVT.getSizeInBits());
|
||||||
if (auto *CFP = dyn_cast<ConstantFPSDNode>(Val))
|
if (auto *CFP = dyn_cast<ConstantFPSDNode>(Val))
|
||||||
Val = DAG.getConstant(
|
Val = DAG.getConstant(
|
||||||
CFP->getValueAPF().bitcastToAPInt().zextOrTrunc(
|
CFP->getValueAPF().bitcastToAPInt().zextOrTrunc(
|
||||||
8 * ElementSizeBytes),
|
ElementSizeBits),
|
||||||
SDLoc(CFP), IntMemVT);
|
SDLoc(CFP), IntMemVT);
|
||||||
else if (auto *C = dyn_cast<ConstantSDNode>(Val))
|
else if (auto *C = dyn_cast<ConstantSDNode>(Val))
|
||||||
Val = DAG.getConstant(
|
Val = DAG.getConstant(
|
||||||
C->getAPIntValue().zextOrTrunc(8 * ElementSizeBytes),
|
C->getAPIntValue().zextOrTrunc(ElementSizeBits),
|
||||||
SDLoc(C), IntMemVT);
|
SDLoc(C), IntMemVT);
|
||||||
}
|
}
|
||||||
// Make sure correctly size type is the correct type.
|
// Make sure correctly size type is the correct type.
|
||||||
|
@ -12716,7 +12716,7 @@ bool DAGCombiner::MergeStoresOfConstantsOrVecElts(
|
||||||
StoreSDNode *St = cast<StoreSDNode>(StoreNodes[Idx].MemNode);
|
StoreSDNode *St = cast<StoreSDNode>(StoreNodes[Idx].MemNode);
|
||||||
|
|
||||||
SDValue Val = St->getValue();
|
SDValue Val = St->getValue();
|
||||||
StoreInt <<= ElementSizeBytes * 8;
|
StoreInt <<= ElementSizeBits;
|
||||||
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Val)) {
|
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Val)) {
|
||||||
StoreInt |= C->getAPIntValue().zextOrTrunc(SizeInBits);
|
StoreInt |= C->getAPIntValue().zextOrTrunc(SizeInBits);
|
||||||
} else if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Val)) {
|
} else if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Val)) {
|
||||||
|
@ -12914,7 +12914,7 @@ bool DAGCombiner::MergeConsecutiveStores(StoreSDNode *St) {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
EVT MemVT = St->getMemoryVT();
|
EVT MemVT = St->getMemoryVT();
|
||||||
int64_t ElementSizeBytes = MemVT.getSizeInBits() / 8;
|
int64_t ElementSizeBytes = MemVT.getStoreSize();
|
||||||
unsigned NumMemElts = MemVT.isVector() ? MemVT.getVectorNumElements() : 1;
|
unsigned NumMemElts = MemVT.isVector() ? MemVT.getVectorNumElements() : 1;
|
||||||
|
|
||||||
if (MemVT.getSizeInBits() * 2 > MaximumLegalStoreInBits)
|
if (MemVT.getSizeInBits() * 2 > MaximumLegalStoreInBits)
|
||||||
|
|
|
@ -4140,7 +4140,7 @@ void SelectionDAGBuilder::visitAtomicLoad(const LoadInst &I) {
|
||||||
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
|
||||||
EVT VT = TLI.getValueType(DAG.getDataLayout(), I.getType());
|
EVT VT = TLI.getValueType(DAG.getDataLayout(), I.getType());
|
||||||
|
|
||||||
if (I.getAlignment() < VT.getSizeInBits() / 8)
|
if (I.getAlignment() < VT.getStoreSize())
|
||||||
report_fatal_error("Cannot generate unaligned atomic load");
|
report_fatal_error("Cannot generate unaligned atomic load");
|
||||||
|
|
||||||
MachineMemOperand *MMO =
|
MachineMemOperand *MMO =
|
||||||
|
@ -4176,7 +4176,7 @@ void SelectionDAGBuilder::visitAtomicStore(const StoreInst &I) {
|
||||||
EVT VT =
|
EVT VT =
|
||||||
TLI.getValueType(DAG.getDataLayout(), I.getValueOperand()->getType());
|
TLI.getValueType(DAG.getDataLayout(), I.getValueOperand()->getType());
|
||||||
|
|
||||||
if (I.getAlignment() < VT.getSizeInBits() / 8)
|
if (I.getAlignment() < VT.getStoreSize())
|
||||||
report_fatal_error("Cannot generate unaligned atomic store");
|
report_fatal_error("Cannot generate unaligned atomic store");
|
||||||
|
|
||||||
SDValue OutChain =
|
SDValue OutChain =
|
||||||
|
|
|
@ -96,7 +96,7 @@ StatepointLoweringState::allocateStackSlot(EVT ValueType,
|
||||||
NumSlotsAllocatedForStatepoints++;
|
NumSlotsAllocatedForStatepoints++;
|
||||||
MachineFrameInfo &MFI = Builder.DAG.getMachineFunction().getFrameInfo();
|
MachineFrameInfo &MFI = Builder.DAG.getMachineFunction().getFrameInfo();
|
||||||
|
|
||||||
unsigned SpillSize = ValueType.getSizeInBits() / 8;
|
unsigned SpillSize = ValueType.getStoreSize();
|
||||||
assert((SpillSize * 8) == ValueType.getSizeInBits() && "Size not in bytes?");
|
assert((SpillSize * 8) == ValueType.getSizeInBits() && "Size not in bytes?");
|
||||||
|
|
||||||
// First look for a previously created stack slot which is not in
|
// First look for a previously created stack slot which is not in
|
||||||
|
|
|
@ -3495,7 +3495,7 @@ TargetLowering::expandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG) const {
|
||||||
// Copy the value to a (aligned) stack slot using (unaligned) integer
|
// Copy the value to a (aligned) stack slot using (unaligned) integer
|
||||||
// loads and stores, then do a (aligned) load from the stack slot.
|
// loads and stores, then do a (aligned) load from the stack slot.
|
||||||
MVT RegVT = getRegisterType(*DAG.getContext(), intVT);
|
MVT RegVT = getRegisterType(*DAG.getContext(), intVT);
|
||||||
unsigned LoadedBytes = LoadedVT.getSizeInBits() / 8;
|
unsigned LoadedBytes = LoadedVT.getStoreSize();
|
||||||
unsigned RegBytes = RegVT.getSizeInBits() / 8;
|
unsigned RegBytes = RegVT.getSizeInBits() / 8;
|
||||||
unsigned NumRegs = (LoadedBytes + RegBytes - 1) / RegBytes;
|
unsigned NumRegs = (LoadedBytes + RegBytes - 1) / RegBytes;
|
||||||
|
|
||||||
|
@ -3650,7 +3650,7 @@ SDValue TargetLowering::expandUnalignedStore(StoreSDNode *ST,
|
||||||
EVT::getIntegerVT(*DAG.getContext(),
|
EVT::getIntegerVT(*DAG.getContext(),
|
||||||
StoredVT.getSizeInBits()));
|
StoredVT.getSizeInBits()));
|
||||||
EVT PtrVT = Ptr.getValueType();
|
EVT PtrVT = Ptr.getValueType();
|
||||||
unsigned StoredBytes = StoredVT.getSizeInBits() / 8;
|
unsigned StoredBytes = StoredVT.getStoreSize();
|
||||||
unsigned RegBytes = RegVT.getSizeInBits() / 8;
|
unsigned RegBytes = RegVT.getSizeInBits() / 8;
|
||||||
unsigned NumRegs = (StoredBytes + RegBytes - 1) / RegBytes;
|
unsigned NumRegs = (StoredBytes + RegBytes - 1) / RegBytes;
|
||||||
|
|
||||||
|
@ -3772,7 +3772,7 @@ TargetLowering::IncrementMemoryAddress(SDValue Addr, SDValue Mask,
|
||||||
AddrVT);
|
AddrVT);
|
||||||
Increment = DAG.getNode(ISD::MUL, DL, AddrVT, Increment, Scale);
|
Increment = DAG.getNode(ISD::MUL, DL, AddrVT, Increment, Scale);
|
||||||
} else
|
} else
|
||||||
Increment = DAG.getConstant(DataVT.getSizeInBits() / 8, DL, AddrVT);
|
Increment = DAG.getConstant(DataVT.getStoreSize(), DL, AddrVT);
|
||||||
|
|
||||||
return DAG.getNode(ISD::ADD, DL, AddrVT, Addr, Increment);
|
return DAG.getNode(ISD::ADD, DL, AddrVT, Addr, Increment);
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,6 @@ namespace {
|
||||||
bool runOnLoop(Loop *L, LPPassManager &LPM) override;
|
bool runOnLoop(Loop *L, LPPassManager &LPM) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
unsigned getStoreSizeInBytes(StoreInst *SI);
|
|
||||||
int getSCEVStride(const SCEVAddRecExpr *StoreEv);
|
int getSCEVStride(const SCEVAddRecExpr *StoreEv);
|
||||||
bool isLegalStore(Loop *CurLoop, StoreInst *SI);
|
bool isLegalStore(Loop *CurLoop, StoreInst *SI);
|
||||||
void collectStores(Loop *CurLoop, BasicBlock *BB,
|
void collectStores(Loop *CurLoop, BasicBlock *BB,
|
||||||
|
@ -1847,13 +1846,6 @@ bool PolynomialMultiplyRecognize::recognize() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned HexagonLoopIdiomRecognize::getStoreSizeInBytes(StoreInst *SI) {
|
|
||||||
uint64_t SizeInBits = DL->getTypeSizeInBits(SI->getValueOperand()->getType());
|
|
||||||
assert(((SizeInBits & 7) || (SizeInBits >> 32) == 0) &&
|
|
||||||
"Don't overflow unsigned.");
|
|
||||||
return (unsigned)SizeInBits >> 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
int HexagonLoopIdiomRecognize::getSCEVStride(const SCEVAddRecExpr *S) {
|
int HexagonLoopIdiomRecognize::getSCEVStride(const SCEVAddRecExpr *S) {
|
||||||
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(S->getOperand(1)))
|
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(S->getOperand(1)))
|
||||||
return SC->getAPInt().getSExtValue();
|
return SC->getAPInt().getSExtValue();
|
||||||
|
@ -1885,7 +1877,7 @@ bool HexagonLoopIdiomRecognize::isLegalStore(Loop *CurLoop, StoreInst *SI) {
|
||||||
int Stride = getSCEVStride(StoreEv);
|
int Stride = getSCEVStride(StoreEv);
|
||||||
if (Stride == 0)
|
if (Stride == 0)
|
||||||
return false;
|
return false;
|
||||||
unsigned StoreSize = getStoreSizeInBytes(SI);
|
unsigned StoreSize = DL->getTypeStoreSize(SI->getValueOperand()->getType());
|
||||||
if (StoreSize != unsigned(std::abs(Stride)))
|
if (StoreSize != unsigned(std::abs(Stride)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1960,7 +1952,7 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
|
||||||
Value *StorePtr = SI->getPointerOperand();
|
Value *StorePtr = SI->getPointerOperand();
|
||||||
auto *StoreEv = cast<SCEVAddRecExpr>(SE->getSCEV(StorePtr));
|
auto *StoreEv = cast<SCEVAddRecExpr>(SE->getSCEV(StorePtr));
|
||||||
unsigned Stride = getSCEVStride(StoreEv);
|
unsigned Stride = getSCEVStride(StoreEv);
|
||||||
unsigned StoreSize = getStoreSizeInBytes(SI);
|
unsigned StoreSize = DL->getTypeStoreSize(SI->getValueOperand()->getType());
|
||||||
if (Stride != StoreSize)
|
if (Stride != StoreSize)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -2812,8 +2812,7 @@ static bool CC_MipsO32(unsigned ValNo, MVT ValVT, MVT LocVT,
|
||||||
llvm_unreachable("Cannot handle this ValVT.");
|
llvm_unreachable("Cannot handle this ValVT.");
|
||||||
|
|
||||||
if (!Reg) {
|
if (!Reg) {
|
||||||
unsigned Offset = State.AllocateStack(ValVT.getSizeInBits() >> 3,
|
unsigned Offset = State.AllocateStack(ValVT.getStoreSize(), OrigAlign);
|
||||||
OrigAlign);
|
|
||||||
State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
|
State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
|
||||||
} else
|
} else
|
||||||
State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
|
State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
|
||||||
|
|
|
@ -334,13 +334,6 @@ bool LoopIdiomRecognize::runOnCountableLoop() {
|
||||||
return MadeChange;
|
return MadeChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned getStoreSizeInBytes(StoreInst *SI, const DataLayout *DL) {
|
|
||||||
uint64_t SizeInBits = DL->getTypeSizeInBits(SI->getValueOperand()->getType());
|
|
||||||
assert(((SizeInBits & 7) || (SizeInBits >> 32) == 0) &&
|
|
||||||
"Don't overflow unsigned.");
|
|
||||||
return (unsigned)SizeInBits >> 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
static APInt getStoreStride(const SCEVAddRecExpr *StoreEv) {
|
static APInt getStoreStride(const SCEVAddRecExpr *StoreEv) {
|
||||||
const SCEVConstant *ConstStride = cast<SCEVConstant>(StoreEv->getOperand(1));
|
const SCEVConstant *ConstStride = cast<SCEVConstant>(StoreEv->getOperand(1));
|
||||||
return ConstStride->getAPInt();
|
return ConstStride->getAPInt();
|
||||||
|
@ -458,7 +451,7 @@ LoopIdiomRecognize::isLegalStore(StoreInst *SI) {
|
||||||
// Check to see if the stride matches the size of the store. If so, then we
|
// Check to see if the stride matches the size of the store. If so, then we
|
||||||
// know that every byte is touched in the loop.
|
// know that every byte is touched in the loop.
|
||||||
APInt Stride = getStoreStride(StoreEv);
|
APInt Stride = getStoreStride(StoreEv);
|
||||||
unsigned StoreSize = getStoreSizeInBytes(SI, DL);
|
unsigned StoreSize = DL->getTypeStoreSize(SI->getValueOperand()->getType());
|
||||||
if (StoreSize != Stride && StoreSize != -Stride)
|
if (StoreSize != Stride && StoreSize != -Stride)
|
||||||
return LegalStoreKind::None;
|
return LegalStoreKind::None;
|
||||||
|
|
||||||
|
@ -597,7 +590,7 @@ bool LoopIdiomRecognize::processLoopStores(SmallVectorImpl<StoreInst *> &SL,
|
||||||
const SCEVAddRecExpr *FirstStoreEv =
|
const SCEVAddRecExpr *FirstStoreEv =
|
||||||
cast<SCEVAddRecExpr>(SE->getSCEV(FirstStorePtr));
|
cast<SCEVAddRecExpr>(SE->getSCEV(FirstStorePtr));
|
||||||
APInt FirstStride = getStoreStride(FirstStoreEv);
|
APInt FirstStride = getStoreStride(FirstStoreEv);
|
||||||
unsigned FirstStoreSize = getStoreSizeInBytes(SL[i], DL);
|
unsigned FirstStoreSize = DL->getTypeStoreSize(SL[i]->getValueOperand()->getType());
|
||||||
|
|
||||||
// See if we can optimize just this store in isolation.
|
// See if we can optimize just this store in isolation.
|
||||||
if (FirstStride == FirstStoreSize || -FirstStride == FirstStoreSize) {
|
if (FirstStride == FirstStoreSize || -FirstStride == FirstStoreSize) {
|
||||||
|
@ -690,7 +683,7 @@ bool LoopIdiomRecognize::processLoopStores(SmallVectorImpl<StoreInst *> &SL,
|
||||||
break;
|
break;
|
||||||
AdjacentStores.insert(I);
|
AdjacentStores.insert(I);
|
||||||
|
|
||||||
StoreSize += getStoreSizeInBytes(I, DL);
|
StoreSize += DL->getTypeStoreSize(I->getValueOperand()->getType());
|
||||||
// Move to the next value in the chain.
|
// Move to the next value in the chain.
|
||||||
I = ConsecutiveChain[I];
|
I = ConsecutiveChain[I];
|
||||||
}
|
}
|
||||||
|
@ -964,7 +957,7 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(StoreInst *SI,
|
||||||
Value *StorePtr = SI->getPointerOperand();
|
Value *StorePtr = SI->getPointerOperand();
|
||||||
const SCEVAddRecExpr *StoreEv = cast<SCEVAddRecExpr>(SE->getSCEV(StorePtr));
|
const SCEVAddRecExpr *StoreEv = cast<SCEVAddRecExpr>(SE->getSCEV(StorePtr));
|
||||||
APInt Stride = getStoreStride(StoreEv);
|
APInt Stride = getStoreStride(StoreEv);
|
||||||
unsigned StoreSize = getStoreSizeInBytes(SI, DL);
|
unsigned StoreSize = DL->getTypeStoreSize(SI->getValueOperand()->getType());
|
||||||
bool NegStride = StoreSize == -Stride;
|
bool NegStride = StoreSize == -Stride;
|
||||||
|
|
||||||
// The store must be feeding a non-volatile load.
|
// The store must be feeding a non-volatile load.
|
||||||
|
|
Loading…
Reference in New Issue