Skip to content

Commit 89c0fe2

Browse files
Merge pull request #55 from CompilerProgramming/develop
Issue 54
2 parents ce25e48 + 17ba8a2 commit 89c0fe2

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

optvm/src/main/java/com/compilerprogramming/ezlang/compiler/ExitSSA.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ private CopyItem isCycle(List<CopyItem> copySet, Register src) {
245245
private void addMoveAtBBEnd(BasicBlock block, Register src, Register dest) {
246246
var inst = new Instruction.Move(new Operand.RegisterOperand(src), new Operand.RegisterOperand(dest));
247247
insertAtEnd(block, inst);
248+
// If the copy instruction is followed by a cbr which uses the old var
249+
// then we need to update the cbr instruction
250+
// This is not specified in the Briggs paper but t
251+
var brInst = block.instructions.getLast();
252+
if (brInst instanceof Instruction.ConditionalBranch cbr) {
253+
cbr.replaceUse(src,dest);
254+
}
248255
}
249256
/* Insert a copy from constant src to dst at end of BB */
250257
private void addMoveAtBBEnd(BasicBlock block, Operand.ConstantOperand src, Register dest) {

optvm/src/test/java/com/compilerprogramming/ezlang/compiler/TestSSATransform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3156,7 +3156,7 @@ func bug(N: Int)
31563156
if %t2_0 goto L3 else goto L4
31573157
L3:
31583158
p_5 = p_1
3159-
if p_1 goto L5 else goto L6
3159+
if p_5 goto L5 else goto L6
31603160
L5:
31613161
%t3_0 = p_1+1
31623162
p_4 = %t3_0

0 commit comments

Comments
 (0)