forked from OSchip/llvm-project
[InstCombine] Make combineLoadToNewType a method; NFC
So it can be reused as part of other combines. In particular for D71164.
This commit is contained in:
parent
652cd7c100
commit
b4dd928ffb
|
@ -467,6 +467,9 @@ public:
|
|||
/// \return true if successful.
|
||||
bool replacePointer(Instruction &I, Value *V);
|
||||
|
||||
LoadInst *combineLoadToNewType(LoadInst &LI, Type *NewTy,
|
||||
const Twine &Suffix = "");
|
||||
|
||||
private:
|
||||
bool shouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const;
|
||||
bool shouldChangeType(Type *From, Type *To) const;
|
||||
|
|
|
@ -449,8 +449,8 @@ static bool isSupportedAtomicType(Type *Ty) {
|
|||
///
|
||||
/// Note that this will create all of the instructions with whatever insert
|
||||
/// point the \c InstCombiner currently is using.
|
||||
static LoadInst *combineLoadToNewType(InstCombiner &IC, LoadInst &LI, Type *NewTy,
|
||||
const Twine &Suffix = "") {
|
||||
LoadInst *InstCombiner::combineLoadToNewType(LoadInst &LI, Type *NewTy,
|
||||
const Twine &Suffix) {
|
||||
assert((!LI.isAtomic() || isSupportedAtomicType(NewTy)) &&
|
||||
"can't fold an atomic load to requested type");
|
||||
|
||||
|
@ -460,16 +460,16 @@ static LoadInst *combineLoadToNewType(InstCombiner &IC, LoadInst &LI, Type *NewT
|
|||
if (!(match(Ptr, m_BitCast(m_Value(NewPtr))) &&
|
||||
NewPtr->getType()->getPointerElementType() == NewTy &&
|
||||
NewPtr->getType()->getPointerAddressSpace() == AS))
|
||||
NewPtr = IC.Builder.CreateBitCast(Ptr, NewTy->getPointerTo(AS));
|
||||
NewPtr = Builder.CreateBitCast(Ptr, NewTy->getPointerTo(AS));
|
||||
|
||||
unsigned Align = LI.getAlignment();
|
||||
if (!Align)
|
||||
// If old load did not have an explicit alignment specified,
|
||||
// manually preserve the implied (ABI) alignment of the load.
|
||||
// Else we may inadvertently incorrectly over-promise alignment.
|
||||
Align = IC.getDataLayout().getABITypeAlignment(LI.getType());
|
||||
Align = getDataLayout().getABITypeAlignment(LI.getType());
|
||||
|
||||
LoadInst *NewLoad = IC.Builder.CreateAlignedLoad(
|
||||
LoadInst *NewLoad = Builder.CreateAlignedLoad(
|
||||
NewTy, NewPtr, Align, LI.isVolatile(), LI.getName() + Suffix);
|
||||
NewLoad->setAtomic(LI.getOrdering(), LI.getSyncScopeID());
|
||||
copyMetadataForLoad(*NewLoad, LI);
|
||||
|
@ -607,9 +607,8 @@ static Instruction *combineLoadToOperationType(InstCombiner &IC, LoadInst &LI) {
|
|||
return SI && SI->getPointerOperand() != &LI &&
|
||||
!SI->getPointerOperand()->isSwiftError();
|
||||
})) {
|
||||
LoadInst *NewLoad = combineLoadToNewType(
|
||||
IC, LI,
|
||||
Type::getIntNTy(LI.getContext(), DL.getTypeStoreSizeInBits(Ty)));
|
||||
LoadInst *NewLoad = IC.combineLoadToNewType(
|
||||
LI, Type::getIntNTy(LI.getContext(), DL.getTypeStoreSizeInBits(Ty)));
|
||||
// Replace all the stores with stores of the newly loaded value.
|
||||
for (auto UI = LI.user_begin(), UE = LI.user_end(); UI != UE;) {
|
||||
auto *SI = cast<StoreInst>(*UI++);
|
||||
|
@ -631,7 +630,7 @@ static Instruction *combineLoadToOperationType(InstCombiner &IC, LoadInst &LI) {
|
|||
if (auto* CI = dyn_cast<CastInst>(LI.user_back()))
|
||||
if (CI->isNoopCast(DL))
|
||||
if (!LI.isAtomic() || isSupportedAtomicType(CI->getDestTy())) {
|
||||
LoadInst *NewLoad = combineLoadToNewType(IC, LI, CI->getDestTy());
|
||||
LoadInst *NewLoad = IC.combineLoadToNewType(LI, CI->getDestTy());
|
||||
CI->replaceAllUsesWith(NewLoad);
|
||||
IC.eraseInstFromFunction(*CI);
|
||||
return &LI;
|
||||
|
@ -659,8 +658,8 @@ static Instruction *unpackLoadToAggregate(InstCombiner &IC, LoadInst &LI) {
|
|||
// If the struct only have one element, we unpack.
|
||||
auto NumElements = ST->getNumElements();
|
||||
if (NumElements == 1) {
|
||||
LoadInst *NewLoad = combineLoadToNewType(IC, LI, ST->getTypeAtIndex(0U),
|
||||
".unpack");
|
||||
LoadInst *NewLoad = IC.combineLoadToNewType(LI, ST->getTypeAtIndex(0U),
|
||||
".unpack");
|
||||
AAMDNodes AAMD;
|
||||
LI.getAAMetadata(AAMD);
|
||||
NewLoad->setAAMetadata(AAMD);
|
||||
|
@ -709,7 +708,7 @@ static Instruction *unpackLoadToAggregate(InstCombiner &IC, LoadInst &LI) {
|
|||
auto *ET = AT->getElementType();
|
||||
auto NumElements = AT->getNumElements();
|
||||
if (NumElements == 1) {
|
||||
LoadInst *NewLoad = combineLoadToNewType(IC, LI, ET, ".unpack");
|
||||
LoadInst *NewLoad = IC.combineLoadToNewType(LI, ET, ".unpack");
|
||||
AAMDNodes AAMD;
|
||||
LI.getAAMetadata(AAMD);
|
||||
NewLoad->setAAMetadata(AAMD);
|
||||
|
@ -1352,7 +1351,7 @@ static bool removeBitcastsFromLoadStoreOnMinMax(InstCombiner &IC,
|
|||
return false;
|
||||
|
||||
IC.Builder.SetInsertPoint(LI);
|
||||
LoadInst *NewLI = combineLoadToNewType(IC, *LI, CmpLoadTy);
|
||||
LoadInst *NewLI = IC.combineLoadToNewType(*LI, CmpLoadTy);
|
||||
// Replace all the stores with stores of the newly loaded value.
|
||||
for (auto *UI : LI->users()) {
|
||||
auto *USI = cast<StoreInst>(UI);
|
||||
|
|
Loading…
Reference in New Issue