// v = 2
// return %v_1 <-- cannot be replaced with v
// ....
if (!(soleUse instanceof ReturnInstr)) {
CopyInstr ci = (CopyInstr)i;
Operand src = ci.getSource();
i.markDead();
instrs.remove();
// Fix up use
Map<Operand, Operand> copyMap = new HashMap<Operand, Operand>();
copyMap.put(v, src);
soleUse.simplifyOperands(copyMap, true);
}
}
}
// Deal with this code pattern:
// 1: %v = ... (not a copy)
// 2: x = %v
// If %v is not used anywhere else, the result of 1. can be updated to use x and 2. can be removed
//
// NOTE: consider this pattern:
// %v = <operand> (copy instr)
// x = %v
// This code will have been captured in the previous if branch which would have deleted %v = 5
// Hence the check for whether the src def instr is dead
else if (i instanceof CopyInstr) {
CopyInstr ci = (CopyInstr)i;
Operand src = ci.getSource();
if (src instanceof TemporaryVariable) {
TemporaryVariable vsrc = (TemporaryVariable)src;
List<Instr> uses = tmpVarUses.get(vsrc);
List<Instr> defs = tmpVarDefs.get(vsrc);
if ((uses.size() == 1) && (defs.size() == 1)) {