1 ; RUN: llc -march=bpfel -mcpu=v4 -gotol-abs-low-bound 0 -verify-machineinstrs -show-mc-encoding < %s | FileCheck %s
3 ; // This test covers all three cases:
4 ; // (1). jmp to another basic block (not the follow-through one)
5 ; // (2). conditional jmp (follow-through and non-follow-through)
6 ; // (3). conditional jmp followed by an unconditional jmp
7 ; // To trigger case (3) the following code is developed which
8 ; // covers case (1) and (2) as well.
9 ; unsigned foo(unsigned a, unsigned b) {
30 ; clang -target bpf -O2 -mcpu=v4 -S -emit-llvm t.c
32 ; Function Attrs: nofree norecurse nosync nounwind memory(none)
33 define dso_local i32 @foo(i32 noundef %a, i32 noundef %b) local_unnamed_addr #0 {
35 %cmp = icmp ult i32 %a, %b
36 br i1 %cmp, label %next, label %next2
38 ; case (3): conditional jmp followed by an unconditional jmp
40 ; CHECK-NEXT: if w1 < w2 goto
41 ; CHECK: gotol LBB0_4 # encoding: [0x06'A',A,A,A,0x00,0x00,0x00,0x00]
42 ; CHECK-NEXT: # fixup A - offset: 0, value: LBB0_4, kind: FK_BPF_PCRel_4
44 begin: ; preds = %next2, %next
45 %s.0 = phi i32 [ %mul3, %next ], [ %mul7, %next2 ]
46 %div = udiv i32 %s.0, %b
47 %cmp1 = icmp ugt i32 %div, %a
48 br i1 %cmp1, label %if.then2, label %next
50 ; case (2): conditional jmp
52 ; CHECK-NEXT: if w0 > w2 goto LBB0_7
54 ; CHECK-LABEL: LBB0_7:
57 ; CHECK-LABEL: LBB0_4:
59 if.then2: ; preds = %begin
60 %mul = mul i32 %div, %div
63 ; case (1): unconditional jmp
67 next: ; preds = %begin, %entry
68 %s.1 = phi i32 [ %b, %entry ], [ %div, %begin ]
69 %mul3 = mul i32 %s.1, %a
70 %cmp4 = icmp ugt i32 %mul3, %b
71 br i1 %cmp4, label %begin, label %next2
73 next2: ; preds = %next, %entry
74 %s.2 = phi i32 [ %mul3, %next ], [ %b, %entry ]
75 %mul7 = mul i32 %s.2, %b
76 %cmp8 = icmp ugt i32 %mul7, %a
77 br i1 %cmp8, label %begin, label %cleanup
79 cleanup: ; preds = %next2, %if.then2
80 %retval.0 = phi i32 [ %mul, %if.then2 ], [ %mul7, %next2 ]
84 attributes #0 = { nofree norecurse nosync nounwind memory(none) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="v4" }
86 !llvm.module.flags = !{!0, !1}
89 !0 = !{i32 1, !"wchar_size", i32 4}
90 !1 = !{i32 7, !"frame-pointer", i32 2}
91 !2 = !{!"clang version 18.0.0 (https://github.com/llvm/llvm-project.git dccf0f74657ce8c50eb1e997bae356c32d7b1ffe)"}