Files
clang-p2996/llvm/test/CodeGen/BPF/adjust-opt-speculative2.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

92 lines
3.4 KiB
LLVM

; RUN: opt -O2 -mtriple=bpf-pc-linux %s | llvm-dis > %t1
; RUN: llc -mcpu=v1 %t1 -o - | FileCheck -check-prefixes=CHECK-COMMON,CHECK %s
; RUN: opt -O2 -mtriple=bpf-pc-linux -bpf-disable-avoid-speculation %s | llvm-dis > %t1
; RUN: llc -mcpu=v1 %t1 -o - | FileCheck -check-prefixes=CHECK-COMMON,CHECK-DISABLE %s
;
; Source:
; unsigned foo();
; ptr test(ptr p) {
; unsigned ret = foo();
; if (ret <= 7)
; p += ret;
; return p;
; }
; Compilation flag:
; clang -target bpf -O2 -S -emit-llvm -Xclang -disable-llvm-passes test.c
; Function Attrs: nounwind
define dso_local ptr @test(ptr %p) #0 {
entry:
%p.addr = alloca ptr, align 8
%ret = alloca i32, align 4
store ptr %p, ptr %p.addr, align 8, !tbaa !2
call void @llvm.lifetime.start.p0(i64 4, ptr %ret) #3
%call = call i32 @foo()
store i32 %call, ptr %ret, align 4, !tbaa !6
%0 = load i32, ptr %ret, align 4, !tbaa !6
%cmp = icmp ule i32 %0, 7
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
%1 = load i32, ptr %ret, align 4, !tbaa !6
%2 = load ptr, ptr %p.addr, align 8, !tbaa !2
%idx.ext = zext i32 %1 to i64
%add.ptr = getelementptr i8, ptr %2, i64 %idx.ext
store ptr %add.ptr, ptr %p.addr, align 8, !tbaa !2
br label %if.end
if.end: ; preds = %if.then, %entry
%3 = load ptr, ptr %p.addr, align 8, !tbaa !2
call void @llvm.lifetime.end.p0(i64 4, ptr %ret) #3
ret ptr %3
}
; CHECK-COMMON: [[REG6:r[0-9]+]] = r1
; CHECK-COMMON: call foo
; CHECK: r0 <<= 32
; CHECK: r0 >>= 32
; CHECK: if r0 > 7 goto [[LABEL:.*]]
; CHECK: [[REG6]] += r0
; CHECK: [[LABEL]]:
; CHECK: r0 = [[REG6]]
; CHECK-DISABLE: [[REG1:r[0-9]+]] = r0
; CHECK-DISABLE: [[REG1]] <<= 32
; CHECK-DISABLE: [[REG1]] >>= 32
; CHECK-DISABLE: [[REG2:r[0-9]+]] = 8
; CHECK-DISABLE: if [[REG2]] > [[REG1]] goto [[LABEL:.*]]
; CHECK-DISABLE: r0 = 0
; CHECK-DISABLE: [[LABEL]]:
; CHECK-DISABLE: r0 <<= 32
; CHECK-DISABLE: r0 >>= 32
; CHECK-DISABLE: [[REG6]] += r0
; CHECK-DISABLE: r0 = [[REG6]]
; CHECK-COMMON: exit
; Function Attrs: argmemonly nounwind willreturn
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
declare dso_local i32 @foo(...) #2
; Function Attrs: argmemonly nounwind willreturn
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
attributes #0 = { nounwind "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { argmemonly nounwind willreturn }
attributes #2 = { "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #3 = { nounwind }
!llvm.module.flags = !{!0}
!llvm.ident = !{!1}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{!"clang version 12.0.0 (https://github.com/llvm/llvm-project.git ca9c5433a6c31e372092fcd8bfd0e4fddd7e8784)"}
!2 = !{!3, !3, i64 0}
!3 = !{!"any pointer", !4, i64 0}
!4 = !{!"omnipotent char", !5, i64 0}
!5 = !{!"Simple C/C++ TBAA"}
!6 = !{!7, !7, i64 0}
!7 = !{!"int", !4, i64 0}