Files
clang-p2996/llvm/test/CodeGen/BPF/objdump_cond_op_2.ll
yonghong-song 7852ebc088 [BPF] Make -mcpu=v3 as the default (#107008)
Before llvm20, (void)__sync_fetch_and_add(...) always generates locked
xadd insns. In linux kernel upstream discussion [1], it is found that
for arm64 architecture, the original semantics of
(void)__sync_fetch_and_add(...), i.e., __atomic_fetch_add(...), is
preferred in order for jit to emit proper native barrier insns.

In llvm commits [2] and [3], (void)__sync_fetch_and_add(...) will
generate the following insns:
  - for cpu v1/v2: locked xadd insns to keep backward compatibility
  - for cpu v3/v4: __atomic_fetch_add() insns

To ensure proper barrier semantics for (void)__sync_fetch_and_add(...),
cpu v3/v4 is recommended.

This patch enables cpu=v3 as the default cpu version. For users wanting
to use cpu v1, -mcpu=v1 needs to be explicitly added to clang/llc
command line.

  [1]
https://lore.kernel.org/bpf/ZqqiQQWRnz7H93Hc@google.com/T/#mb68d67bc8f39e35a0c3db52468b9de59b79f021f
  [2] https://github.com/llvm/llvm-project/pull/101428
  [3] https://github.com/llvm/llvm-project/pull/106494
2024-09-03 07:15:18 -07:00

37 lines
1.0 KiB
LLVM

; RUN: llc -mtriple=bpfel -mcpu=v1 -filetype=obj -o - %s | llvm-objdump --no-print-imm-hex -d - | FileCheck %s
; Source Code:
; int test(int a, int b) {
; int s = 0;
; while (a < b) { s++; a += s; b -= s; }
; return s;
; }
define i32 @test(i32, i32) local_unnamed_addr #0 {
; CHECK-LABEL: <test>:
%3 = icmp slt i32 %0, %1
br i1 %3, label %4, label %13
; <label>:4: ; preds = %2
br label %5
; CHECK: if r4 s>= r3 goto +10 <test+0x90>
; <label>:5: ; preds = %4, %5
%6 = phi i32 [ %9, %5 ], [ 0, %4 ]
%7 = phi i32 [ %11, %5 ], [ %1, %4 ]
%8 = phi i32 [ %10, %5 ], [ %0, %4 ]
%9 = add nuw nsw i32 %6, 1
%10 = add nsw i32 %9, %8
%11 = sub nsw i32 %7, %9
%12 = icmp slt i32 %10, %11
br i1 %12, label %5, label %13
; CHECK: r1 = r3
; CHECK: if r2 s> r3 goto -10 <test+0x40>
; <label>:13: ; preds = %5, %2
%14 = phi i32 [ 0, %2 ], [ %9, %5 ]
ret i32 %14
; CHECK: exit
}
attributes #0 = { norecurse nounwind readnone }