Skip to content

Commit 024f351

Browse files
eddyz87Yonghong Song
authored andcommitted
[BPF] Don't insert unreachable 'goto' after JX instructions
Update BPFInstrInfo::analyzeBranch() to comply with TargetInstrInfo::analyzeBranch() requirements for JX instruction: if branch instruction can't be categorized as a conditional with true/false branches -- return true. Because of this bug MachineBlockPlacement transformation inserted an additional unreachabe jump after JX, e.g.: bb.1.entry: ... JX killed $r1, %jump-table.0 JMP %bb.2 Additionally, isNotDuplicable annotation is necessary to avoid machine level transformations creating several JX instruction copies. Such copies would refer to the same jump table and would make it not possible to calculate jump offsets inside the table. Files triggering such duplication are present in kernel selftests.
1 parent a8180a8 commit 024f351

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

llvm/lib/Target/BPF/BPFInstrInfo.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@ bool BPFInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
181181
if (!isUnpredicatedTerminator(*I))
182182
break;
183183

184-
// If a JX insn, we're done.
185-
if (I->getOpcode() == BPF::JX)
186-
break;
184+
// From base method doc: ... returning true if it cannot be understood ...
185+
// Indirect branch has multiple destinations and no true/false concepts.
186+
if (I->isIndirectBranch())
187+
return true;
187188

188189
// A terminator that isn't a branch can't easily be handled
189190
// by this analysis.

llvm/lib/Target/BPF/BPFInstrInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ defm JSLE : J<BPF_JSLE, "s<=", BPF_CC_LE, BPF_CC_LE_32>;
308308
defm JSET : J<BPF_JSET, "&", NoCond, NoCond>;
309309
def JCOND : JMP_JCOND<BPF_JCOND, "may_goto", []>;
310310

311-
let isIndirectBranch = 1 in {
311+
let isIndirectBranch = 1, isBarrier = 1, isNotDuplicable = 1 in {
312312
def JX : JMP_IND<BPF_JA, "gotox", [(BPFBrJt tjumptable:$jt, i64:$dst)]>;
313313
}
314314
}

0 commit comments

Comments
 (0)