Index: vm/jitrino/src/optimizer/ssa/SSA.cpp =================================================================== --- vm/jitrino/src/optimizer/ssa/SSA.cpp (revision 475137) +++ vm/jitrino/src/optimizer/ssa/SSA.cpp (working copy) @@ -103,6 +103,29 @@ {}; }; + +// Checks that phi insts can start from the second or third position only +// and goes in a row +bool SSABuilder::phiInstsOnRightPositionsInBB(Node* node) { + Inst* inst = (Inst*)node->getSecondInst(); + if(inst && !inst->isPhi()) { + // try the next one (third) + inst = inst->getNextInst(); + } + // skip all phis + while ( inst!=NULL && inst->isPhi() ) { + inst = inst->getNextInst(); + } + // 'true' only if there is no any other phis in the node + while ( inst!=NULL ) { + if(inst->isPhi()) { + return false; + } + inst = inst->getNextInst(); + } + return true; +} + // // find def sites (blocks) of var operand // @@ -601,7 +624,16 @@ bool SSABuilder::checkForTrivialPhis(Node *node, StlVector &changedVars) { + // Check that phi insts can start from the second or third position only + // and goes in a row + assert(phiInstsOnRightPositionsInBB(node)); + Inst* phi = (Inst*)node->getSecondInst(); + if(phi && !phi->isPhi()) { + // try the next one (third) + phi = phi->getNextInst(); + } + bool removedPhi = false; #ifdef DEBUG_SSA if (Log::isEnabled()) { @@ -669,7 +701,16 @@ StlVector *changedVars, StlVector *removedVars) { + // Check that phi insts can start from the second or third position only + // and goes in a row + assert(phiInstsOnRightPositionsInBB(node)); + Inst* phi = (Inst*)node->getSecondInst(); + if(phi && !phi->isPhi()) { + // try the next one (third) + phi = phi->getNextInst(); + } + Inst *nextphi = NULL; #ifdef DEBUG_SSA if (Log::isEnabled()) { Index: vm/jitrino/src/optimizer/ssa/SSA.h =================================================================== --- vm/jitrino/src/optimizer/ssa/SSA.h (revision 475137) +++ vm/jitrino/src/optimizer/ssa/SSA.h (working copy) @@ -105,6 +105,7 @@ bool fixupVars(ControlFlowGraph* fg, MethodDesc& methodDesc); static void deconvertSSA(ControlFlowGraph* fg,OpndManager& opndManager); static void splitSsaWebs(ControlFlowGraph* fg,OpndManager& opndManager); + static bool phiInstsOnRightPositionsInBB(Node* node); private: void findDefSites(DefSites& allDefSites); void insertPhi(DefSites& allDefSites);