mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 04:30:12 +00:00
Convert instcombine from using using getAnalysis<TargetData> to
getAnalysisIfAvailable<TargetData>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76676 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
295643b805
commit
ce9fe9fae5
@ -157,12 +157,11 @@ namespace {
|
|||||||
bool DoOneIteration(Function &F, unsigned ItNum);
|
bool DoOneIteration(Function &F, unsigned ItNum);
|
||||||
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.addRequired<TargetData>();
|
|
||||||
AU.addPreservedID(LCSSAID);
|
AU.addPreservedID(LCSSAID);
|
||||||
AU.setPreservesCFG();
|
AU.setPreservesCFG();
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetData &getTargetData() const { return *TD; }
|
TargetData *getTargetData() const { return TD; }
|
||||||
|
|
||||||
// Visitation implementation - Implement instruction combining for different
|
// Visitation implementation - Implement instruction combining for different
|
||||||
// instruction types. The semantics are as follows:
|
// instruction types. The semantics are as follows:
|
||||||
@ -460,7 +459,7 @@ isEliminableCastPair(
|
|||||||
const Type *DstTy, ///< The target type for the second cast instruction
|
const Type *DstTy, ///< The target type for the second cast instruction
|
||||||
TargetData *TD ///< The target data for pointer size
|
TargetData *TD ///< The target data for pointer size
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const Type *SrcTy = CI->getOperand(0)->getType(); // A from above
|
const Type *SrcTy = CI->getOperand(0)->getType(); // A from above
|
||||||
const Type *MidTy = CI->getType(); // B from above
|
const Type *MidTy = CI->getType(); // B from above
|
||||||
|
|
||||||
@ -469,7 +468,8 @@ isEliminableCastPair(
|
|||||||
Instruction::CastOps secondOp = Instruction::CastOps(opcode);
|
Instruction::CastOps secondOp = Instruction::CastOps(opcode);
|
||||||
|
|
||||||
unsigned Res = CastInst::isEliminableCastPair(firstOp, secondOp, SrcTy, MidTy,
|
unsigned Res = CastInst::isEliminableCastPair(firstOp, secondOp, SrcTy, MidTy,
|
||||||
DstTy, TD->getIntPtrType());
|
DstTy,
|
||||||
|
TD ? TD->getIntPtrType() : 0);
|
||||||
|
|
||||||
// We don't want to form an inttoptr or ptrtoint that converts to an integer
|
// We don't want to form an inttoptr or ptrtoint that converts to an integer
|
||||||
// type that differs from the pointer size.
|
// type that differs from the pointer size.
|
||||||
@ -489,7 +489,7 @@ static bool ValueRequiresCast(Instruction::CastOps opcode, const Value *V,
|
|||||||
|
|
||||||
// If this is another cast that can be eliminated, it isn't codegen either.
|
// If this is another cast that can be eliminated, it isn't codegen either.
|
||||||
if (const CastInst *CI = dyn_cast<CastInst>(V))
|
if (const CastInst *CI = dyn_cast<CastInst>(V))
|
||||||
if (isEliminableCastPair(CI, opcode, Ty, TD))
|
if (isEliminableCastPair(CI, opcode, Ty, TD))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -5350,7 +5350,7 @@ static bool SubWithOverflow(Constant *&Result, Constant *In1,
|
|||||||
/// code necessary to compute the offset from the base pointer (without adding
|
/// code necessary to compute the offset from the base pointer (without adding
|
||||||
/// in the base pointer). Return the result as a signed integer of intptr size.
|
/// in the base pointer). Return the result as a signed integer of intptr size.
|
||||||
static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
|
static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
|
||||||
TargetData &TD = IC.getTargetData();
|
TargetData &TD = *IC.getTargetData();
|
||||||
gep_type_iterator GTI = gep_type_begin(GEP);
|
gep_type_iterator GTI = gep_type_begin(GEP);
|
||||||
const Type *IntPtrTy = TD.getIntPtrType();
|
const Type *IntPtrTy = TD.getIntPtrType();
|
||||||
LLVMContext *Context = IC.getContext();
|
LLVMContext *Context = IC.getContext();
|
||||||
@ -5438,7 +5438,7 @@ static Value *EmitGEPOffset(User *GEP, Instruction &I, InstCombiner &IC) {
|
|||||||
///
|
///
|
||||||
static Value *EvaluateGEPOffsetExpression(User *GEP, Instruction &I,
|
static Value *EvaluateGEPOffsetExpression(User *GEP, Instruction &I,
|
||||||
InstCombiner &IC) {
|
InstCombiner &IC) {
|
||||||
TargetData &TD = IC.getTargetData();
|
TargetData &TD = *IC.getTargetData();
|
||||||
gep_type_iterator GTI = gep_type_begin(GEP);
|
gep_type_iterator GTI = gep_type_begin(GEP);
|
||||||
|
|
||||||
// Check to see if this gep only has a single variable index. If so, and if
|
// Check to see if this gep only has a single variable index. If so, and if
|
||||||
@ -5544,7 +5544,7 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
|
|||||||
RHS = BCI->getOperand(0);
|
RHS = BCI->getOperand(0);
|
||||||
|
|
||||||
Value *PtrBase = GEPLHS->getOperand(0);
|
Value *PtrBase = GEPLHS->getOperand(0);
|
||||||
if (PtrBase == RHS) {
|
if (TD && PtrBase == RHS) {
|
||||||
// ((gep Ptr, OFFSET) cmp Ptr) ---> (OFFSET cmp 0).
|
// ((gep Ptr, OFFSET) cmp Ptr) ---> (OFFSET cmp 0).
|
||||||
// This transformation (ignoring the base and scales) is valid because we
|
// This transformation (ignoring the base and scales) is valid because we
|
||||||
// know pointers can't overflow. See if we can output an optimized form.
|
// know pointers can't overflow. See if we can output an optimized form.
|
||||||
@ -5635,7 +5635,8 @@ Instruction *InstCombiner::FoldGEPICmp(User *GEPLHS, Value *RHS,
|
|||||||
|
|
||||||
// Only lower this if the icmp is the only user of the GEP or if we expect
|
// Only lower this if the icmp is the only user of the GEP or if we expect
|
||||||
// the result to fold to a constant!
|
// the result to fold to a constant!
|
||||||
if ((isa<ConstantExpr>(GEPLHS) || GEPLHS->hasOneUse()) &&
|
if (TD &&
|
||||||
|
(isa<ConstantExpr>(GEPLHS) || GEPLHS->hasOneUse()) &&
|
||||||
(isa<ConstantExpr>(GEPRHS) || GEPRHS->hasOneUse())) {
|
(isa<ConstantExpr>(GEPRHS) || GEPRHS->hasOneUse())) {
|
||||||
// ((gep Ptr, OFFSET1) cmp (gep Ptr, OFFSET2) ---> (OFFSET1 cmp OFFSET2)
|
// ((gep Ptr, OFFSET1) cmp (gep Ptr, OFFSET2) ---> (OFFSET1 cmp OFFSET2)
|
||||||
Value *L = EmitGEPOffset(GEPLHS, I, *this);
|
Value *L = EmitGEPOffset(GEPLHS, I, *this);
|
||||||
@ -7168,8 +7169,8 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
|
|||||||
|
|
||||||
// Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if the
|
// Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if the
|
||||||
// integer type is the same size as the pointer type.
|
// integer type is the same size as the pointer type.
|
||||||
if (LHSCI->getOpcode() == Instruction::PtrToInt &&
|
if (TD && LHSCI->getOpcode() == Instruction::PtrToInt &&
|
||||||
getTargetData().getPointerSizeInBits() ==
|
TD->getPointerSizeInBits() ==
|
||||||
cast<IntegerType>(DestTy)->getBitWidth()) {
|
cast<IntegerType>(DestTy)->getBitWidth()) {
|
||||||
Value *RHSOp = 0;
|
Value *RHSOp = 0;
|
||||||
if (Constant *RHSC = dyn_cast<Constant>(ICI.getOperand(1))) {
|
if (Constant *RHSC = dyn_cast<Constant>(ICI.getOperand(1))) {
|
||||||
@ -7792,7 +7793,10 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI,
|
|||||||
EraseInstFromFunction(*User);
|
EraseInstFromFunction(*User);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This requires TargetData to get the alloca alignment and size information.
|
||||||
|
if (!TD) return 0;
|
||||||
|
|
||||||
// Get the type really allocated and the type casted to.
|
// Get the type really allocated and the type casted to.
|
||||||
const Type *AllocElTy = AI.getAllocatedType();
|
const Type *AllocElTy = AI.getAllocatedType();
|
||||||
const Type *CastElTy = PTy->getElementType();
|
const Type *CastElTy = PTy->getElementType();
|
||||||
@ -8124,6 +8128,7 @@ static const Type *FindElementAtOffset(const Type *Ty, int64_t Offset,
|
|||||||
SmallVectorImpl<Value*> &NewIndices,
|
SmallVectorImpl<Value*> &NewIndices,
|
||||||
const TargetData *TD,
|
const TargetData *TD,
|
||||||
LLVMContext *Context) {
|
LLVMContext *Context) {
|
||||||
|
if (!TD) return 0;
|
||||||
if (!Ty->isSized()) return 0;
|
if (!Ty->isSized()) return 0;
|
||||||
|
|
||||||
// Start with the index over the outer type. Note that the type size
|
// Start with the index over the outer type. Note that the type size
|
||||||
@ -8197,7 +8202,7 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) {
|
|||||||
// GEP computes a constant offset, see if we can convert these three
|
// GEP computes a constant offset, see if we can convert these three
|
||||||
// instructions into fewer. This typically happens with unions and other
|
// instructions into fewer. This typically happens with unions and other
|
||||||
// non-type-safe code.
|
// non-type-safe code.
|
||||||
if (GEP->hasOneUse() && isa<BitCastInst>(GEP->getOperand(0))) {
|
if (TD && GEP->hasOneUse() && isa<BitCastInst>(GEP->getOperand(0))) {
|
||||||
if (GEP->hasAllConstantIndices()) {
|
if (GEP->hasAllConstantIndices()) {
|
||||||
// We are guaranteed to get a constant from EmitGEPOffset.
|
// We are guaranteed to get a constant from EmitGEPOffset.
|
||||||
ConstantInt *OffsetV =
|
ConstantInt *OffsetV =
|
||||||
@ -8863,7 +8868,8 @@ Instruction *InstCombiner::visitPtrToInt(PtrToIntInst &CI) {
|
|||||||
// trunc to be exposed to other transforms. Don't do this for extending
|
// trunc to be exposed to other transforms. Don't do this for extending
|
||||||
// ptrtoint's, because we don't know if the target sign or zero extends its
|
// ptrtoint's, because we don't know if the target sign or zero extends its
|
||||||
// pointers.
|
// pointers.
|
||||||
if (CI.getType()->getScalarSizeInBits() < TD->getPointerSizeInBits()) {
|
if (TD &&
|
||||||
|
CI.getType()->getScalarSizeInBits() < TD->getPointerSizeInBits()) {
|
||||||
Value *P = InsertNewInstBefore(new PtrToIntInst(CI.getOperand(0),
|
Value *P = InsertNewInstBefore(new PtrToIntInst(CI.getOperand(0),
|
||||||
TD->getIntPtrType(),
|
TD->getIntPtrType(),
|
||||||
"tmp"), CI);
|
"tmp"), CI);
|
||||||
@ -8879,7 +8885,8 @@ Instruction *InstCombiner::visitIntToPtr(IntToPtrInst &CI) {
|
|||||||
// allows the trunc to be exposed to other transforms. Don't do this for
|
// allows the trunc to be exposed to other transforms. Don't do this for
|
||||||
// extending inttoptr's, because we don't know if the target sign or zero
|
// extending inttoptr's, because we don't know if the target sign or zero
|
||||||
// extends to pointers.
|
// extends to pointers.
|
||||||
if (CI.getOperand(0)->getType()->getScalarSizeInBits() >
|
if (TD &&
|
||||||
|
CI.getOperand(0)->getType()->getScalarSizeInBits() >
|
||||||
TD->getPointerSizeInBits()) {
|
TD->getPointerSizeInBits()) {
|
||||||
Value *P = InsertNewInstBefore(new TruncInst(CI.getOperand(0),
|
Value *P = InsertNewInstBefore(new TruncInst(CI.getOperand(0),
|
||||||
TD->getIntPtrType(),
|
TD->getIntPtrType(),
|
||||||
@ -9667,7 +9674,7 @@ Instruction *InstCombiner::SimplifyMemTransfer(MemIntrinsic *MI) {
|
|||||||
// integer datatype.
|
// integer datatype.
|
||||||
if (Value *Op = getBitCastOperand(MI->getOperand(1))) {
|
if (Value *Op = getBitCastOperand(MI->getOperand(1))) {
|
||||||
const Type *SrcETy = cast<PointerType>(Op->getType())->getElementType();
|
const Type *SrcETy = cast<PointerType>(Op->getType())->getElementType();
|
||||||
if (SrcETy->isSized() && TD->getTypeStoreSize(SrcETy) == Size) {
|
if (TD && SrcETy->isSized() && TD->getTypeStoreSize(SrcETy) == Size) {
|
||||||
// The SrcETy might be something like {{{double}}} or [1 x double]. Rip
|
// The SrcETy might be something like {{{double}}} or [1 x double]. Rip
|
||||||
// down through these levels if so.
|
// down through these levels if so.
|
||||||
while (!SrcETy->isSingleValueType()) {
|
while (!SrcETy->isSingleValueType()) {
|
||||||
@ -10000,7 +10007,7 @@ static bool isSafeToEliminateVarargsCast(const CallSite CS,
|
|||||||
const Type* DstTy = cast<PointerType>(CI->getType())->getElementType();
|
const Type* DstTy = cast<PointerType>(CI->getType())->getElementType();
|
||||||
if (!SrcTy->isSized() || !DstTy->isSized())
|
if (!SrcTy->isSized() || !DstTy->isSized())
|
||||||
return false;
|
return false;
|
||||||
if (TD->getTypeAllocSize(SrcTy) != TD->getTypeAllocSize(DstTy))
|
if (!TD || TD->getTypeAllocSize(SrcTy) != TD->getTypeAllocSize(DstTy))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -10110,8 +10117,10 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
|
|||||||
if (Callee->isDeclaration() &&
|
if (Callee->isDeclaration() &&
|
||||||
// Conversion is ok if changing from one pointer type to another or from
|
// Conversion is ok if changing from one pointer type to another or from
|
||||||
// a pointer to an integer of the same size.
|
// a pointer to an integer of the same size.
|
||||||
!((isa<PointerType>(OldRetTy) || OldRetTy == TD->getIntPtrType()) &&
|
!((isa<PointerType>(OldRetTy) || !TD ||
|
||||||
(isa<PointerType>(NewRetTy) || NewRetTy == TD->getIntPtrType())))
|
OldRetTy == TD->getIntPtrType()) &&
|
||||||
|
(isa<PointerType>(NewRetTy) || !TD ||
|
||||||
|
NewRetTy == TD->getIntPtrType())))
|
||||||
return false; // Cannot transform this return value.
|
return false; // Cannot transform this return value.
|
||||||
|
|
||||||
if (!Caller->use_empty() &&
|
if (!Caller->use_empty() &&
|
||||||
@ -10157,8 +10166,8 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
|
|||||||
// Converting from one pointer type to another or between a pointer and an
|
// Converting from one pointer type to another or between a pointer and an
|
||||||
// integer of the same size is safe even if we do not have a body.
|
// integer of the same size is safe even if we do not have a body.
|
||||||
bool isConvertible = ActTy == ParamTy ||
|
bool isConvertible = ActTy == ParamTy ||
|
||||||
((isa<PointerType>(ParamTy) || ParamTy == TD->getIntPtrType()) &&
|
(TD && ((isa<PointerType>(ParamTy) || ParamTy == TD->getIntPtrType()) &&
|
||||||
(isa<PointerType>(ActTy) || ActTy == TD->getIntPtrType()));
|
(isa<PointerType>(ActTy) || ActTy == TD->getIntPtrType())));
|
||||||
if (Callee->isDeclaration() && !isConvertible) return false;
|
if (Callee->isDeclaration() && !isConvertible) return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10965,7 +10974,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
gep_type_iterator GTI = gep_type_begin(GEP);
|
gep_type_iterator GTI = gep_type_begin(GEP);
|
||||||
for (User::op_iterator i = GEP.op_begin() + 1, e = GEP.op_end();
|
for (User::op_iterator i = GEP.op_begin() + 1, e = GEP.op_end();
|
||||||
i != e; ++i, ++GTI) {
|
i != e; ++i, ++GTI) {
|
||||||
if (isa<SequentialType>(*GTI)) {
|
if (TD && isa<SequentialType>(*GTI)) {
|
||||||
if (CastInst *CI = dyn_cast<CastInst>(*i)) {
|
if (CastInst *CI = dyn_cast<CastInst>(*i)) {
|
||||||
if (CI->getOpcode() == Instruction::ZExt ||
|
if (CI->getOpcode() == Instruction::ZExt ||
|
||||||
CI->getOpcode() == Instruction::SExt) {
|
CI->getOpcode() == Instruction::SExt) {
|
||||||
@ -11054,7 +11063,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
} else if (Constant *GO1C = dyn_cast<Constant>(GO1)) {
|
} else if (Constant *GO1C = dyn_cast<Constant>(GO1)) {
|
||||||
GO1 =
|
GO1 =
|
||||||
Context->getConstantExprIntegerCast(GO1C, SO1->getType(), true);
|
Context->getConstantExprIntegerCast(GO1C, SO1->getType(), true);
|
||||||
} else {
|
} else if (TD) {
|
||||||
unsigned PS = TD->getPointerSizeInBits();
|
unsigned PS = TD->getPointerSizeInBits();
|
||||||
if (TD->getTypeSizeInBits(SO1->getType()) == PS) {
|
if (TD->getTypeSizeInBits(SO1->getType()) == PS) {
|
||||||
// Convert GO1 to SO1's type.
|
// Convert GO1 to SO1's type.
|
||||||
@ -11161,7 +11170,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
// into: %t1 = getelementptr [2 x i32]* %str, i32 0, i32 %V; bitcast
|
// into: %t1 = getelementptr [2 x i32]* %str, i32 0, i32 %V; bitcast
|
||||||
const Type *SrcElTy = cast<PointerType>(X->getType())->getElementType();
|
const Type *SrcElTy = cast<PointerType>(X->getType())->getElementType();
|
||||||
const Type *ResElTy=cast<PointerType>(PtrOp->getType())->getElementType();
|
const Type *ResElTy=cast<PointerType>(PtrOp->getType())->getElementType();
|
||||||
if (isa<ArrayType>(SrcElTy) &&
|
if (TD && isa<ArrayType>(SrcElTy) &&
|
||||||
TD->getTypeAllocSize(cast<ArrayType>(SrcElTy)->getElementType()) ==
|
TD->getTypeAllocSize(cast<ArrayType>(SrcElTy)->getElementType()) ==
|
||||||
TD->getTypeAllocSize(ResElTy)) {
|
TD->getTypeAllocSize(ResElTy)) {
|
||||||
Value *Idx[2];
|
Value *Idx[2];
|
||||||
@ -11178,7 +11187,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
// (where tmp = 8*tmp2) into:
|
// (where tmp = 8*tmp2) into:
|
||||||
// getelementptr [100 x double]* %arr, i32 0, i32 %tmp2; bitcast
|
// getelementptr [100 x double]* %arr, i32 0, i32 %tmp2; bitcast
|
||||||
|
|
||||||
if (isa<ArrayType>(SrcElTy) && ResElTy == Type::Int8Ty) {
|
if (TD && isa<ArrayType>(SrcElTy) && ResElTy == Type::Int8Ty) {
|
||||||
uint64_t ArrayEltSize =
|
uint64_t ArrayEltSize =
|
||||||
TD->getTypeAllocSize(cast<ArrayType>(SrcElTy)->getElementType());
|
TD->getTypeAllocSize(cast<ArrayType>(SrcElTy)->getElementType());
|
||||||
|
|
||||||
@ -11244,7 +11253,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
|||||||
/// into a gep of the original struct. This is important for SROA and alias
|
/// into a gep of the original struct. This is important for SROA and alias
|
||||||
/// analysis of unions. If "A" is also a bitcast, wait for A/X to be merged.
|
/// analysis of unions. If "A" is also a bitcast, wait for A/X to be merged.
|
||||||
if (BitCastInst *BCI = dyn_cast<BitCastInst>(PtrOp)) {
|
if (BitCastInst *BCI = dyn_cast<BitCastInst>(PtrOp)) {
|
||||||
if (!isa<BitCastInst>(BCI->getOperand(0)) && GEP.hasAllConstantIndices()) {
|
if (TD &&
|
||||||
|
!isa<BitCastInst>(BCI->getOperand(0)) && GEP.hasAllConstantIndices()) {
|
||||||
// Determine how much the GEP moves the pointer. We are guaranteed to get
|
// Determine how much the GEP moves the pointer. We are guaranteed to get
|
||||||
// a constant back from EmitGEPOffset.
|
// a constant back from EmitGEPOffset.
|
||||||
ConstantInt *OffsetV =
|
ConstantInt *OffsetV =
|
||||||
@ -11333,7 +11343,7 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isa<AllocaInst>(AI) && AI.getAllocatedType()->isSized()) {
|
if (TD && isa<AllocaInst>(AI) && AI.getAllocatedType()->isSized()) {
|
||||||
// If alloca'ing a zero byte object, replace the alloca with a null pointer.
|
// If alloca'ing a zero byte object, replace the alloca with a null pointer.
|
||||||
// Note that we only do this for alloca's, because malloc should allocate
|
// Note that we only do this for alloca's, because malloc should allocate
|
||||||
// and return a unique pointer, even for a zero byte allocation.
|
// and return a unique pointer, even for a zero byte allocation.
|
||||||
@ -11456,13 +11466,14 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI,
|
|||||||
SrcPTy = SrcTy->getElementType();
|
SrcPTy = SrcTy->getElementType();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((SrcPTy->isInteger() || isa<PointerType>(SrcPTy) ||
|
if (IC.getTargetData() &&
|
||||||
|
(SrcPTy->isInteger() || isa<PointerType>(SrcPTy) ||
|
||||||
isa<VectorType>(SrcPTy)) &&
|
isa<VectorType>(SrcPTy)) &&
|
||||||
// Do not allow turning this into a load of an integer, which is then
|
// Do not allow turning this into a load of an integer, which is then
|
||||||
// casted to a pointer, this pessimizes pointer analysis a lot.
|
// casted to a pointer, this pessimizes pointer analysis a lot.
|
||||||
(isa<PointerType>(SrcPTy) == isa<PointerType>(LI.getType())) &&
|
(isa<PointerType>(SrcPTy) == isa<PointerType>(LI.getType())) &&
|
||||||
IC.getTargetData().getTypeSizeInBits(SrcPTy) ==
|
IC.getTargetData()->getTypeSizeInBits(SrcPTy) ==
|
||||||
IC.getTargetData().getTypeSizeInBits(DestPTy)) {
|
IC.getTargetData()->getTypeSizeInBits(DestPTy)) {
|
||||||
|
|
||||||
// Okay, we are casting from one integer or pointer type to another of
|
// Okay, we are casting from one integer or pointer type to another of
|
||||||
// the same size. Instead of casting the pointer before the load, cast
|
// the same size. Instead of casting the pointer before the load, cast
|
||||||
@ -11482,12 +11493,14 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
|
|||||||
Value *Op = LI.getOperand(0);
|
Value *Op = LI.getOperand(0);
|
||||||
|
|
||||||
// Attempt to improve the alignment.
|
// Attempt to improve the alignment.
|
||||||
unsigned KnownAlign =
|
if (TD) {
|
||||||
GetOrEnforceKnownAlignment(Op, TD->getPrefTypeAlignment(LI.getType()));
|
unsigned KnownAlign =
|
||||||
if (KnownAlign >
|
GetOrEnforceKnownAlignment(Op, TD->getPrefTypeAlignment(LI.getType()));
|
||||||
(LI.getAlignment() == 0 ? TD->getABITypeAlignment(LI.getType()) :
|
if (KnownAlign >
|
||||||
LI.getAlignment()))
|
(LI.getAlignment() == 0 ? TD->getABITypeAlignment(LI.getType()) :
|
||||||
LI.setAlignment(KnownAlign);
|
LI.getAlignment()))
|
||||||
|
LI.setAlignment(KnownAlign);
|
||||||
|
}
|
||||||
|
|
||||||
// load (cast X) --> cast (load X) iff safe
|
// load (cast X) --> cast (load X) iff safe
|
||||||
if (isa<CastInst>(Op))
|
if (isa<CastInst>(Op))
|
||||||
@ -11667,10 +11680,11 @@ static Instruction *InstCombineStoreToCast(InstCombiner &IC, StoreInst &SI) {
|
|||||||
|
|
||||||
// If the pointers point into different address spaces or if they point to
|
// If the pointers point into different address spaces or if they point to
|
||||||
// values with different sizes, we can't do the transformation.
|
// values with different sizes, we can't do the transformation.
|
||||||
if (SrcTy->getAddressSpace() !=
|
if (!IC.getTargetData() ||
|
||||||
|
SrcTy->getAddressSpace() !=
|
||||||
cast<PointerType>(CI->getType())->getAddressSpace() ||
|
cast<PointerType>(CI->getType())->getAddressSpace() ||
|
||||||
IC.getTargetData().getTypeSizeInBits(SrcPTy) !=
|
IC.getTargetData()->getTypeSizeInBits(SrcPTy) !=
|
||||||
IC.getTargetData().getTypeSizeInBits(DestPTy))
|
IC.getTargetData()->getTypeSizeInBits(DestPTy))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Okay, we are casting from one integer or pointer type to another of
|
// Okay, we are casting from one integer or pointer type to another of
|
||||||
@ -11800,12 +11814,14 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attempt to improve the alignment.
|
// Attempt to improve the alignment.
|
||||||
unsigned KnownAlign =
|
if (TD) {
|
||||||
GetOrEnforceKnownAlignment(Ptr, TD->getPrefTypeAlignment(Val->getType()));
|
unsigned KnownAlign =
|
||||||
if (KnownAlign >
|
GetOrEnforceKnownAlignment(Ptr, TD->getPrefTypeAlignment(Val->getType()));
|
||||||
(SI.getAlignment() == 0 ? TD->getABITypeAlignment(Val->getType()) :
|
if (KnownAlign >
|
||||||
SI.getAlignment()))
|
(SI.getAlignment() == 0 ? TD->getABITypeAlignment(Val->getType()) :
|
||||||
SI.setAlignment(KnownAlign);
|
SI.getAlignment()))
|
||||||
|
SI.setAlignment(KnownAlign);
|
||||||
|
}
|
||||||
|
|
||||||
// Do really simple DSE, to catch cases where there are several consecutive
|
// Do really simple DSE, to catch cases where there are several consecutive
|
||||||
// stores to the same location, separated by a few arithmetic operations. This
|
// stores to the same location, separated by a few arithmetic operations. This
|
||||||
@ -12884,7 +12900,7 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
|
|||||||
|
|
||||||
bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
|
bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
TD = &getAnalysis<TargetData>();
|
TD = getAnalysisIfAvailable<TargetData>();
|
||||||
|
|
||||||
DEBUG(DOUT << "\n\nINSTCOMBINE ITERATION #" << Iteration << " on "
|
DEBUG(DOUT << "\n\nINSTCOMBINE ITERATION #" << Iteration << " on "
|
||||||
<< F.getNameStr() << "\n");
|
<< F.getNameStr() << "\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user