mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:42:57 +01:00
Refactor this method a bit, and correct a test that was completely wrong but happened to work out anyways. :-)
llvm-svn: 47321
This commit is contained in:
parent
99e0b1c063
commit
6196cdcb48
@ -1083,6 +1083,8 @@ static bool isReturnSlotOptznProfitable(Value* dest, MemCpyInst* cpy) {
|
|||||||
/// rather than using memcpy
|
/// rather than using memcpy
|
||||||
bool GVN::performReturnSlotOptzn(MemCpyInst* cpy, CallInst* C,
|
bool GVN::performReturnSlotOptzn(MemCpyInst* cpy, CallInst* C,
|
||||||
SmallVector<Instruction*, 4>& toErase) {
|
SmallVector<Instruction*, 4>& toErase) {
|
||||||
|
// Deliberately get the source and destination with bitcasts stripped away,
|
||||||
|
// because we'll need to do type comparisons based on the underlying type.
|
||||||
Value* cpyDest = cpy->getDest();
|
Value* cpyDest = cpy->getDest();
|
||||||
Value* cpySrc = cpy->getSource();
|
Value* cpySrc = cpy->getSource();
|
||||||
CallSite CS = CallSite::get(C);
|
CallSite CS = CallSite::get(C);
|
||||||
@ -1097,23 +1099,25 @@ bool GVN::performReturnSlotOptzn(MemCpyInst* cpy, CallInst* C,
|
|||||||
!CS.paramHasAttr(1, ParamAttr::NoAlias | ParamAttr::StructRet))
|
!CS.paramHasAttr(1, ParamAttr::NoAlias | ParamAttr::StructRet))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// We only perform the transformation if it will be profitable.
|
|
||||||
if (!isReturnSlotOptznProfitable(cpyDest, cpy))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// Check that something sneaky is not happening involving casting
|
// Check that something sneaky is not happening involving casting
|
||||||
// return slot types around.
|
// return slot types around.
|
||||||
if (CS.getArgument(0)->getType() != cpyDest->getType())
|
if (CS.getArgument(0)->getType() != cpyDest->getType())
|
||||||
return false;
|
return false;
|
||||||
|
// sret --> pointer
|
||||||
|
const PointerType* PT = cast<PointerType>(cpyDest->getType());
|
||||||
|
|
||||||
// We can only perform the transformation if the size of the memcpy
|
// We can only perform the transformation if the size of the memcpy
|
||||||
// is constant and equal to the size of the structure.
|
// is constant and equal to the size of the structure.
|
||||||
if (!isa<ConstantInt>(cpy->getLength()))
|
ConstantInt* cpyLength = dyn_cast<ConstantInt>(cpy->getLength());
|
||||||
|
if (!cpyLength)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ConstantInt* cpyLength = cast<ConstantInt>(cpy->getLength());
|
|
||||||
TargetData& TD = getAnalysis<TargetData>();
|
TargetData& TD = getAnalysis<TargetData>();
|
||||||
if (TD.getTypeStoreSize(cpyDest->getType()) == cpyLength->getZExtValue())
|
if (TD.getTypeStoreSize(PT->getElementType()) != cpyLength->getZExtValue())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// We only perform the transformation if it will be profitable.
|
||||||
|
if (!isReturnSlotOptznProfitable(cpyDest, cpy))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// In addition to knowing that the call does not access the return slot
|
// In addition to knowing that the call does not access the return slot
|
||||||
|
Loading…
Reference in New Issue
Block a user