forked from OSchip/llvm-project
[VNCoercion] avoid creating bitcast for zero offsets [NFCI]
This could previously make it more complicated for ConstantFolding later, leading to a higher likelyhood it would have to reject the expression, even though zero seems like probably the common case here. Differential Revision: https://reviews.llvm.org/D59730
This commit is contained in:
parent
19f01a4847
commit
e244f86f4d
|
@ -412,12 +412,14 @@ int analyzeLoadFromClobberingMemInst(Type *LoadTy, Value *LoadPtr,
|
|||
unsigned AS = Src->getType()->getPointerAddressSpace();
|
||||
// Otherwise, see if we can constant fold a load from the constant with the
|
||||
// offset applied as appropriate.
|
||||
Src =
|
||||
ConstantExpr::getBitCast(Src, Type::getInt8PtrTy(Src->getContext(), AS));
|
||||
Constant *OffsetCst =
|
||||
ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
|
||||
Src = ConstantExpr::getGetElementPtr(Type::getInt8Ty(Src->getContext()), Src,
|
||||
OffsetCst);
|
||||
if (Offset) {
|
||||
Src = ConstantExpr::getBitCast(Src,
|
||||
Type::getInt8PtrTy(Src->getContext(), AS));
|
||||
Constant *OffsetCst =
|
||||
ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
|
||||
Src = ConstantExpr::getGetElementPtr(Type::getInt8Ty(Src->getContext()),
|
||||
Src, OffsetCst);
|
||||
}
|
||||
Src = ConstantExpr::getBitCast(Src, PointerType::get(LoadTy, AS));
|
||||
if (ConstantFoldLoadFromConstPtr(Src, LoadTy, DL))
|
||||
return Offset;
|
||||
|
@ -587,16 +589,18 @@ T *getMemInstValueForLoadHelper(MemIntrinsic *SrcInst, unsigned Offset,
|
|||
// Otherwise, this is a memcpy/memmove from a constant global.
|
||||
MemTransferInst *MTI = cast<MemTransferInst>(SrcInst);
|
||||
Constant *Src = cast<Constant>(MTI->getSource());
|
||||
unsigned AS = Src->getType()->getPointerAddressSpace();
|
||||
|
||||
unsigned AS = Src->getType()->getPointerAddressSpace();
|
||||
// Otherwise, see if we can constant fold a load from the constant with the
|
||||
// offset applied as appropriate.
|
||||
Src =
|
||||
ConstantExpr::getBitCast(Src, Type::getInt8PtrTy(Src->getContext(), AS));
|
||||
Constant *OffsetCst =
|
||||
ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
|
||||
Src = ConstantExpr::getGetElementPtr(Type::getInt8Ty(Src->getContext()), Src,
|
||||
OffsetCst);
|
||||
if (Offset) {
|
||||
Src = ConstantExpr::getBitCast(Src,
|
||||
Type::getInt8PtrTy(Src->getContext(), AS));
|
||||
Constant *OffsetCst =
|
||||
ConstantInt::get(Type::getInt64Ty(Src->getContext()), (unsigned)Offset);
|
||||
Src = ConstantExpr::getGetElementPtr(Type::getInt8Ty(Src->getContext()),
|
||||
Src, OffsetCst);
|
||||
}
|
||||
Src = ConstantExpr::getBitCast(Src, PointerType::get(LoadTy, AS));
|
||||
return ConstantFoldLoadFromConstPtr(Src, LoadTy, DL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue