recursively phi translate bitcast operands too, for consistency.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90016 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-11-27 20:25:30 +00:00
parent 807d2fa1eb
commit 5141421e38

View File

@ -693,21 +693,22 @@ static bool isPHITranslatable(Instruction *Inst) {
// We can handle bitcast of a PHI, but the PHI needs to be in the same block // We can handle bitcast of a PHI, but the PHI needs to be in the same block
// as the bitcast. // as the bitcast.
if (BitCastInst *BC = dyn_cast<BitCastInst>(Inst)) if (BitCastInst *BC = dyn_cast<BitCastInst>(Inst)) {
// FIXME: Allow any phi translatable operand. Instruction *OpI = dyn_cast<Instruction>(BC->getOperand(0));
if (PHINode *PN = dyn_cast<PHINode>(BC->getOperand(0))) if (OpI == 0 || OpI->getParent() != Inst->getParent())
if (PN->getParent() == BC->getParent())
return true; return true;
return isPHITranslatable(OpI);
}
// We can translate a GEP if all of its operands defined in this block are phi // We can translate a GEP if all of its operands defined in this block are phi
// translatable. // translatable.
if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) { if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) {
for (unsigned i = 0, e = GEP->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = GEP->getNumOperands(); i != e; ++i) {
Instruction *GEPOpI = dyn_cast<Instruction>(GEP->getOperand(i)); Instruction *OpI = dyn_cast<Instruction>(GEP->getOperand(i));
if (GEPOpI == 0 || GEPOpI->getParent() != Inst->getParent()) if (OpI == 0 || OpI->getParent() != Inst->getParent())
continue; continue;
if (!isPHITranslatable(GEPOpI)) if (!isPHITranslatable(OpI))
return false; return false;
} }
return true; return true;
@ -715,10 +716,10 @@ static bool isPHITranslatable(Instruction *Inst) {
if (Inst->getOpcode() == Instruction::Add && if (Inst->getOpcode() == Instruction::Add &&
isa<ConstantInt>(Inst->getOperand(1))) { isa<ConstantInt>(Inst->getOperand(1))) {
Instruction *GEPOpI = dyn_cast<Instruction>(Inst->getOperand(0)); Instruction *OpI = dyn_cast<Instruction>(Inst->getOperand(0));
if (GEPOpI == 0 || GEPOpI->getParent() != Inst->getParent()) if (OpI == 0 || OpI->getParent() != Inst->getParent())
return true; return true;
return isPHITranslatable(GEPOpI); return isPHITranslatable(OpI);
} }
// cerr << "MEMDEP: Could not PHI translate: " << *Pointer; // cerr << "MEMDEP: Could not PHI translate: " << *Pointer;
@ -745,9 +746,9 @@ PHITranslatePointer(Value *InVal, BasicBlock *CurBB, BasicBlock *Pred,
// Handle bitcast of PHI. // Handle bitcast of PHI.
if (BitCastInst *BC = dyn_cast<BitCastInst>(Inst)) { if (BitCastInst *BC = dyn_cast<BitCastInst>(Inst)) {
// FIXME: Recurse! // PHI translate the input operand.
PHINode *BCPN = cast<PHINode>(BC->getOperand(0)); Value *PHIIn = PHITranslatePointer(BC->getOperand(0), CurBB, Pred, TD);
Value *PHIIn = BCPN->getIncomingValueForBlock(Pred); if (PHIIn == 0) return 0;
// Constants are trivial to phi translate. // Constants are trivial to phi translate.
if (Constant *C = dyn_cast<Constant>(PHIIn)) if (Constant *C = dyn_cast<Constant>(PHIIn))
@ -779,14 +780,10 @@ PHITranslatePointer(Value *InVal, BasicBlock *CurBB, BasicBlock *Pred,
} }
// If the operand is a phi node, do phi translation. // If the operand is a phi node, do phi translation.
if (Value *InOp = PHITranslatePointer(GEPOp, CurBB, Pred, TD)) { Value *InOp = PHITranslatePointer(GEPOp, CurBB, Pred, TD);
GEPOps.push_back(InOp); if (InOp == 0) return 0;
continue;
}
// Otherwise, we can't PHI translate this random value defined in this GEPOps.push_back(InOp);
// block.
return 0;
} }
// Simplify the GEP to handle 'gep x, 0' -> x etc. // Simplify the GEP to handle 'gep x, 0' -> x etc.