mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-06 01:24:35 +00:00
Remove false optimization that basically broke everything
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1219 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -65,6 +65,8 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
|
|||||||
// ExpressionConvertableToType - Return true if it is possible
|
// ExpressionConvertableToType - Return true if it is possible
|
||||||
bool ExpressionConvertableToType(Value *V, const Type *Ty,
|
bool ExpressionConvertableToType(Value *V, const Type *Ty,
|
||||||
ValueTypeCache &CTMap) {
|
ValueTypeCache &CTMap) {
|
||||||
|
if (V->getType() == Ty) return true; // Expression already correct type!
|
||||||
|
|
||||||
// Expression type must be holdable in a register.
|
// Expression type must be holdable in a register.
|
||||||
if (!isFirstClassType(Ty))
|
if (!isFirstClassType(Ty))
|
||||||
return false;
|
return false;
|
||||||
@ -73,16 +75,6 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
|
|||||||
if (CTMI != CTMap.end()) return CTMI->second == Ty;
|
if (CTMI != CTMap.end()) return CTMI->second == Ty;
|
||||||
CTMap[V] = Ty;
|
CTMap[V] = Ty;
|
||||||
|
|
||||||
// Expressions are only convertable if all of the users of the expression can
|
|
||||||
// have this value converted. This makes use of the map to avoid infinite
|
|
||||||
// recursion.
|
|
||||||
//
|
|
||||||
if (isa<Instruction>(V)) {
|
|
||||||
for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I)
|
|
||||||
if (!OperandConvertableToType(*I, V, Ty, CTMap))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Instruction *I = dyn_cast<Instruction>(V);
|
Instruction *I = dyn_cast<Instruction>(V);
|
||||||
if (I == 0) {
|
if (I == 0) {
|
||||||
// It's not an instruction, check to see if it's a constant... all constants
|
// It's not an instruction, check to see if it's a constant... all constants
|
||||||
@ -96,7 +88,16 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
|
|||||||
|
|
||||||
return false; // Otherwise, we can't convert!
|
return false; // Otherwise, we can't convert!
|
||||||
}
|
}
|
||||||
if (I->getType() == Ty) return false; // Expression already correct type!
|
|
||||||
|
// Expressions are only convertable if all of the users of the expression can
|
||||||
|
// have this value converted. This makes use of the map to avoid infinite
|
||||||
|
// recursion.
|
||||||
|
//
|
||||||
|
if (isa<Instruction>(V)) {
|
||||||
|
for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I)
|
||||||
|
if (!OperandConvertableToType(*I, V, Ty, CTMap))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
switch (I->getOpcode()) {
|
switch (I->getOpcode()) {
|
||||||
case Instruction::Cast:
|
case Instruction::Cast:
|
||||||
@ -116,7 +117,13 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
|
|||||||
|
|
||||||
case Instruction::Load: {
|
case Instruction::Load: {
|
||||||
LoadInst *LI = cast<LoadInst>(I);
|
LoadInst *LI = cast<LoadInst>(I);
|
||||||
if (LI->hasIndices()) return false;
|
if (LI->hasIndices()) {
|
||||||
|
// We can't convert a load expression if it has indices... unless they are
|
||||||
|
// all zero.
|
||||||
|
const vector<ConstPoolVal*> &CPV = LI->getIndices();
|
||||||
|
for (unsigned i = 0; i < CPV.size(); ++i)
|
||||||
|
if (!CPV[i]->isNullValue()) return false;
|
||||||
|
}
|
||||||
|
|
||||||
return ExpressionConvertableToType(LI->getPtrOperand(),
|
return ExpressionConvertableToType(LI->getPtrOperand(),
|
||||||
PointerType::get(Ty), CTMap);
|
PointerType::get(Ty), CTMap);
|
||||||
@ -226,7 +233,15 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
|
|||||||
|
|
||||||
case Instruction::Load: {
|
case Instruction::Load: {
|
||||||
LoadInst *LI = cast<LoadInst>(I);
|
LoadInst *LI = cast<LoadInst>(I);
|
||||||
assert(!LI->hasIndices());
|
#ifndef NDEBUG
|
||||||
|
if (LI->hasIndices()) {
|
||||||
|
// We can't convert a load expression if it has indices... unless they are
|
||||||
|
// all zero.
|
||||||
|
const vector<ConstPoolVal*> &CPV = LI->getIndices();
|
||||||
|
for (unsigned i = 0; i < CPV.size(); ++i)
|
||||||
|
assert(CPV[i]->isNullValue() && "Load index not 0!");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Res = new LoadInst(ConstPoolVal::getNullConstant(PointerType::get(Ty)),
|
Res = new LoadInst(ConstPoolVal::getNullConstant(PointerType::get(Ty)),
|
||||||
Name);
|
Name);
|
||||||
VMC.ExprMap[I] = Res;
|
VMC.ExprMap[I] = Res;
|
||||||
@ -393,7 +408,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
|
|||||||
}
|
}
|
||||||
// FALLTHROUGH
|
// FALLTHROUGH
|
||||||
case Instruction::Sub: {
|
case Instruction::Sub: {
|
||||||
CTMap[I] = Ty;
|
|
||||||
Value *OtherOp = I->getOperand((V == I->getOperand(0)) ? 1 : 0);
|
Value *OtherOp = I->getOperand((V == I->getOperand(0)) ? 1 : 0);
|
||||||
return RetValConvertableToType(I, Ty, CTMap) &&
|
return RetValConvertableToType(I, Ty, CTMap) &&
|
||||||
ExpressionConvertableToType(OtherOp, Ty, CTMap);
|
ExpressionConvertableToType(OtherOp, Ty, CTMap);
|
||||||
@ -408,7 +422,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
|
|||||||
// FALL THROUGH
|
// FALL THROUGH
|
||||||
case Instruction::Shl:
|
case Instruction::Shl:
|
||||||
assert(I->getOperand(0) == V);
|
assert(I->getOperand(0) == V);
|
||||||
CTMap[I] = Ty;
|
|
||||||
return RetValConvertableToType(I, Ty, CTMap);
|
return RetValConvertableToType(I, Ty, CTMap);
|
||||||
|
|
||||||
case Instruction::Load:
|
case Instruction::Load:
|
||||||
@ -432,8 +445,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
|
|||||||
// See if the leaf type is compatible with the old return type...
|
// See if the leaf type is compatible with the old return type...
|
||||||
if (TD.getTypeSize(Ty) != TD.getTypeSize(LI->getType()))
|
if (TD.getTypeSize(Ty) != TD.getTypeSize(LI->getType()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CTMap[LI] = Ty;
|
|
||||||
return RetValConvertableToType(LI, Ty, CTMap);
|
return RetValConvertableToType(LI, Ty, CTMap);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -442,7 +453,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
|
|||||||
if (TD.getTypeSize(PVTy) != TD.getTypeSize(LI->getType()))
|
if (TD.getTypeSize(PVTy) != TD.getTypeSize(LI->getType()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
CTMap[LI] = PVTy;
|
|
||||||
return RetValConvertableToType(LI, PVTy, CTMap);
|
return RetValConvertableToType(LI, PVTy, CTMap);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -473,7 +483,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
|
|||||||
}
|
}
|
||||||
|
|
||||||
case Instruction::PHINode: {
|
case Instruction::PHINode: {
|
||||||
CTMap[I] = Ty;
|
|
||||||
PHINode *PN = cast<PHINode>(I);
|
PHINode *PN = cast<PHINode>(I);
|
||||||
for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i)
|
for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i)
|
||||||
if (!ExpressionConvertableToType(PN->getIncomingValue(i), Ty, CTMap))
|
if (!ExpressionConvertableToType(PN->getIncomingValue(i), Ty, CTMap))
|
||||||
|
Reference in New Issue
Block a user