- // Determine whether 'Inst' is an input to our PHI translatable expression.
- bool isInput = std::count(InstInputs.begin(), InstInputs.end(), Inst);
-
- // If 'Inst' is not defined in this block, it is either an input, or an
- // intermediate result.
- if (Inst->getParent() != CurBB) {
- // If it is an input, then it remains an input.
+ // If 'Inst' is defined in this block, it must be an input that needs to be
+ // phi translated or an intermediate expression that needs to be incorporated
+ // into the expression.
+ if (Inst->getParent() == CurBB) {
+ assert(std::count(InstInputs.begin(), InstInputs.end(), Inst) &&
+ "Not an input?");
+
+ // If this is a PHI, go ahead and translate it.
+ if (PHINode *PN = dyn_cast<PHINode>(Inst))
+ return PN->getIncomingValueForBlock(PredBB);
+
+
+ // If this is a non-phi value, and it is analyzable, we can incorporate it
+ // into the expression by making all instruction operands be inputs.
+ if (!CanPHITrans(Inst))
+ return 0;
+
+ // Okay, we can incorporate it, this instruction is no longer an input.
+ InstInputs.erase(std::find(InstInputs.begin(), InstInputs.end(), Inst));
+
+ // All instruction operands are now inputs (and of course, they may also be
+ // defined in this block, so they may need to be phi translated themselves.
+ for (unsigned i = 0, e = Inst->getNumOperands(); i != e; ++i)
+ if (Instruction *Op = dyn_cast<Instruction>(Inst->getOperand(i)))
+ InstInputs.push_back(Op);
+
+ } else {
+ // Determine whether 'Inst' is an input to our PHI translatable expression.
+ bool isInput = std::count(InstInputs.begin(), InstInputs.end(), Inst);
+
+ // If it is an input defined in a different block, then it remains an input.