Program: 150086
Project: 150086
Buggy source:
/** 
 * Work around some problems with PEI-generated values and  handlers.  Namely, if a PEI has a return value, rename the result register before and after the PEI in order to reflect the fact that the PEI may not actually assign the result register.
 */
private void patchPEIgeneratedValues(){
  if (!ir.hasReachableExceptionHandlers())   return;
  HashSet needed=new HashSet(4);
  OPT_BasicBlockEnumeration blocks=ir.getBasicBlocks();
  while (blocks.hasMoreElements()) {
    OPT_BasicBlock block=blocks.next();
    if (block.getExceptionalOut().hasMoreElements()) {
      OPT_Instruction pei=block.lastRealInstruction();
      if (pei != null && pei.isPEI() && ResultCarrier.conforms(pei)) {
        boolean copyNeeded=false;
        OPT_RegisterOperand v=ResultCarrier.getResult(pei);
        if (v != null) {
          OPT_Register orig=v.register;
{
            OPT_BasicBlockEnumeration out=block.getApplicableExceptionalOut(pei);
            while (out.hasMoreElements()) {
              OPT_BasicBlock exp=out.next();
              OPT_LiveSet explive=live.getLiveInfo(exp).in();
              if (explive.contains(orig)) {
                copyNeeded=true;
                break;
              }
            }
          }
          if (copyNeeded) {
            OPT_BasicBlockEnumeration out=block.getApplicableExceptionalOut(pei);
            while (out.hasMoreElements()) {
              OPT_BasicBlock exp=out.next();
              needed.add(new OPT_Pair(exp,v));
            }
          }
        }
      }
    }
  }
  Iterator copies=needed.iterator();
  while (copies.hasNext()) {
    OPT_Pair copy=(OPT_Pair)copies.next();
    OPT_BasicBlock inBlock=(OPT_BasicBlock)copy.first;
    OPT_RegisterOperand registerOp=(OPT_RegisterOperand)copy.second;
    VM_TypeReference type=registerOp.type;
    OPT_Register register=registerOp.register;
    OPT_Register temp=ir.regpool.getReg(register);
    inBlock.prependInstruction(OPT_SSA.makeMoveInstruction(ir,register,temp,type));
    OPT_LiveAnalysis.BBLiveElement inl=live.getLiveInfo(inBlock);
    inl.gen().add(new OPT_RegisterOperand(temp,type));
    inl.in().add(new OPT_RegisterOperand(temp,type));
    OPT_BasicBlockEnumeration outBlocks=inBlock.getIn();
    while (outBlocks.hasMoreElements()) {
      OPT_BasicBlock outBlock=outBlocks.next();
      OPT_Instruction x=OPT_SSA.makeMoveInstruction(ir,temp,register,type);
      OPT_SSA.addAtEnd(ir,outBlock,x,true);
      OPT_LiveAnalysis.BBLiveElement ol=live.getLiveInfo(outBlock);
      ol.BBKillSet().add(new OPT_RegisterOperand(temp,type));
    }
  }
}

Fixed version (ground truth):
/** 
 * Work around some problems with PEI-generated values and  handlers.  Namely, if a PEI has a return value, rename the result register before and after the PEI in order to reflect the fact that the PEI may not actually assign the result register.
 */
private void patchPEIgeneratedValues(){
  if (!ir.hasReachableExceptionHandlers())   return;
  HashSet needed=new HashSet(4);
  OPT_BasicBlockEnumeration blocks=ir.getBasicBlocks();
  while (blocks.hasMoreElements()) {
    OPT_BasicBlock block=blocks.next();
    if (block.getExceptionalOut().hasMoreElements()) {
      OPT_Instruction pei=block.lastRealInstruction();
      if (pei != null && pei.isPEI() && ResultCarrier.conforms(pei)) {
        boolean copyNeeded=false;
        OPT_RegisterOperand v=ResultCarrier.getResult(pei);
        if (v != null) {
          OPT_Register orig=v.register;
{
            OPT_BasicBlockEnumeration out=block.getApplicableExceptionalOut(pei);
            while (out.hasMoreElements()) {
              OPT_BasicBlock exp=out.next();
              OPT_LiveSet explive=live.getLiveInfo(exp).in();
              if (explive.contains(orig)) {
                copyNeeded=true;
                break;
              }
            }
          }
          if (copyNeeded) {
            OPT_BasicBlockEnumeration out=block.getApplicableExceptionalOut(pei);
            while (out.hasMoreElements()) {
              OPT_BasicBlock exp=out.next();
              needed.add(new OPT_Pair(exp,v));
            }
          }
        }
      }
    }
  }
  if (!needed.isEmpty()) {
    for (Iterator copies=needed.iterator(); copies.hasNext(); ) {
      OPT_Pair copy=(OPT_Pair)copies.next();
      OPT_BasicBlock inBlock=(OPT_BasicBlock)copy.first;
      OPT_RegisterOperand registerOp=(OPT_RegisterOperand)copy.second;
      VM_TypeReference type=registerOp.type;
      OPT_Register register=registerOp.register;
      OPT_Register temp=ir.regpool.getReg(register);
      inBlock.prependInstruction(OPT_SSA.makeMoveInstruction(ir,register,temp,type));
      OPT_BasicBlockEnumeration outBlocks=inBlock.getIn();
      while (outBlocks.hasMoreElements()) {
        OPT_BasicBlock outBlock=outBlocks.next();
        OPT_Instruction x=OPT_SSA.makeMoveInstruction(ir,temp,register,type);
        OPT_SSA.addAtEnd(ir,outBlock,x,true);
      }
    }
    prepare();
  }
}