Skip to content
This repository was archived by the owner on Sep 2, 2018. It is now read-only.

Commit eb79a90

Browse files
author
Dylan McKay
committed
[AVR] Fixed bug in AVRBranchSelector
It wasn't taking into account that for PC-relative branches, we had to compensate for the size of the current instruction. This was leading to some branches to not be expanded into bigger branches, and causing MC to fail.
1 parent e2a9559 commit eb79a90

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/Target/AVR/AVRBranchSelector.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ bool AVRBSel::runOnMachineFunction(MachineFunction &Fn)
180180
}
181181
}
182182

183+
if(isCondBranch(Opc))
184+
BranchSize -= 2; // take the size of the current instruction.
185+
183186
assert(!(BranchSize & 1)
184187
&& "BranchSize should have an even number of bytes");
185188
// If this branch is in range, ignore it.
@@ -214,9 +217,10 @@ bool AVRBSel::runOnMachineFunction(MachineFunction &Fn)
214217
PI->getOperand(0).setImm(4);
215218
}
216219
}
217-
}
218-
else
219-
{
220+
} else {
221+
222+
assert(isCondBranch(Opc) && "opcode should be a conditional branch");
223+
220224
unsigned BrCCOffs;
221225
// Determine if we can reach the destination block with a rjmp,
222226
// otherwise a jmp instruction is needed.

0 commit comments

Comments
 (0)