Skip to content

Commit 914ca5e

Browse files
author
Yonghong Song
committed
Ensure correct may_goto asm format
Check AsmOpPieces[1] to ensure may_goto asm format correct.
1 parent af8076c commit 914ca5e

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

llvm/lib/Target/BPF/BPFMIPeephole.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,10 @@ bool BPFMIPreEmitPeephole::removeMayGotoZero() {
710710
// The asm insn must be a may_goto insn.
711711
SmallVector<StringRef, 4> AsmOpPieces;
712712
SplitString(AsmPieces[0], AsmOpPieces, " ");
713-
if (AsmOpPieces[0] != "may_goto")
713+
if (AsmOpPieces.size() != 2 || AsmOpPieces[0] != "may_goto")
714+
continue;
715+
// Enforce the format of 'may_goto <label>'.
716+
if (AsmOpPieces[1] != "${0:l}" && AsmOpPieces[1] != "$0")
714717
continue;
715718

716719
// Get the may_goto branch target.
File renamed without changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: llc -mtriple=bpfel -mcpu=v3 -filetype=obj -o - %s | llvm-objdump --no-show-raw-insn -d - | FileCheck %s
2+
3+
@j = dso_local local_unnamed_addr global i32 0, align 4
4+
5+
define dso_local noundef i32 @foo() local_unnamed_addr {
6+
entry:
7+
callbr void asm sideeffect "may_goto $0", "!i"()
8+
to label %for.body [label %for.cond.cleanup]
9+
10+
for.cond.cleanup: ; preds = %for.body.2, %for.body.2, %for.body.1, %for.body, %entry
11+
ret i32 0
12+
13+
for.body: ; preds = %entry
14+
callbr void asm sideeffect "may_goto $0", "!i"()
15+
to label %for.body.1 [label %for.cond.cleanup]
16+
17+
for.body.1: ; preds = %for.body
18+
callbr void asm sideeffect "may_goto $0", "!i"()
19+
to label %for.body.2 [label %for.cond.cleanup]
20+
21+
for.body.2: ; preds = %for.body.1
22+
callbr void asm sideeffect "may_goto $0", "!i"()
23+
to label %for.cond.cleanup [label %for.cond.cleanup]
24+
}
25+
26+
; CHECK: 0: w0 = 0x0
27+
; CHECK-NEXT: 1: exit

0 commit comments

Comments
 (0)