[llvm] [BPF] Support Jump Table (PR #149715)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 07:58:10 PDT 2025
================
@@ -0,0 +1,91 @@
+; Checks generated using command:
+; llvm/utils/update_test_body.py llvm/test/CodeGen/BPF/jump_table_blockaddr.ll
+
+; RUN: rm -rf %t && split-file %s %t && cd %t
+; RUN: llc -march=bpf -mcpu=v4 < test.ll | FileCheck %s
+;
+; Source code:
+; int bar(int a) {
+; __label__ l1, l2;
+; void * volatile tgt;
+; int ret = 0;
+; if (a)
+; tgt = &&l1; // synthetic jump table generated here
+; else
+; tgt = &&l2; // another synthetic jump table
+; goto *tgt;
+; l1: ret += 1;
+; l2: ret += 2;
+; return ret;
+; }
+;
+; Compilation Flags:
+; clang --target=bpf -mcpu=v4 -O2 -emit-llvm -S test.c
+
+.ifdef GEN
+;--- test.ll
+define dso_local range(i32 2, 4) i32 @bar(i32 noundef %a) local_unnamed_addr{
+entry:
+ %tgt = alloca ptr, align 8
+ %tobool.not = icmp eq i32 %a, 0
+ %. = select i1 %tobool.not, ptr blockaddress(@bar, %l2), ptr blockaddress(@bar, %l1)
+ store volatile ptr %., ptr %tgt, align 8
+ %tgt.0.tgt.0.tgt.0.tgt.0. = load volatile ptr, ptr %tgt, align 8
+ indirectbr ptr %tgt.0.tgt.0.tgt.0.tgt.0., [label %l1, label %l2]
+
+l1: ; preds = %entry
+ br label %l2
+
+l2: ; preds = %l1, %entry
+ %ret.0 = phi i32 [ 3, %l1 ], [ 2, %entry ]
+ ret i32 %ret.0
+}
+
+;--- gen
+echo ""
+echo "; Generated checks follow"
+echo ";"
+llc -march=bpf -mcpu=v4 < test.ll \
+ | awk '/# -- End function/ {p=0} /@function/ {p=1} p {print "; CHECK" ": " $0}'
+
+.endif
+
+; Generated checks follow
+;
+; CHECK: .type bar, at function
+; CHECK: bar: # @bar
+; CHECK: .Lbar$local:
+; CHECK: .type .Lbar$local, at function
+; CHECK: .cfi_startproc
+; CHECK: # %bb.0: # %entry
+; CHECK: r2 = BPF.JT.0.0 ll
+; CHECK: r2 = *(u64 *)(r2 + 0)
----------------
yonghong-song wrote:
I think we are fine here. If anything changed, the CHECKs can be easily regenerated with `update_test_body.py` script. Specific register numbers are helpful to ensure asm code correctness.
https://github.com/llvm/llvm-project/pull/149715
More information about the llvm-commits
mailing list