[llvm] 795bbb3 - [BPF] fix a bug in BPFMISimplifyPatchable pass with -O0
Tom Stellard via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 30 13:13:51 PST 2020
On 01/30/2020 08:29 AM, Yonghong Song via llvm-commits wrote:
>
> Author: Yonghong Song
> Date: 2020-01-30T08:28:39-08:00
> New Revision: 795bbb366266e83d2bea8dc04c19919b52ab3a2a
>
Is this something we should backport to the 10.0 branch?
-Tom
> URL: https://github.com/llvm/llvm-project/commit/795bbb366266e83d2bea8dc04c19919b52ab3a2a
> DIFF: https://github.com/llvm/llvm-project/commit/795bbb366266e83d2bea8dc04c19919b52ab3a2a.diff
>
> LOG: [BPF] fix a bug in BPFMISimplifyPatchable pass with -O0
>
> The recommended optimization level for BPF programs
> is O2 since (1). BPF is running inside the kernel and
> linux kernel won't work at -O0 level, and (2). Verifier
> is not able to handle O0 code properly, e.g., potential
> large stack size and a lot of spills.
>
> But we should keep -O0 at least compiling.
> This patch fixed a bug in BPFMISimplifyPatchable phase
> where with -O0, a segmentation fault will happen for a
> simple program like:
> int test(int a, int b) { return a + b; }
>
> A test case is added to capture such a case.
>
> Differential Revision: https://reviews.llvm.org/D73681
>
> Added:
> llvm/test/CodeGen/BPF/optnone-1.ll
>
> Modified:
> llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
>
> Removed:
>
>
>
> ################################################################################
> diff --git a/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp b/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
> index 5310f0f07b65..29abc9303a62 100644
> --- a/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
> +++ b/llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
> @@ -70,9 +70,10 @@ struct BPFMISimplifyPatchable : public MachineFunctionPass {
> public:
> // Main entry point for this pass.
> bool runOnMachineFunction(MachineFunction &MF) override {
> - if (!skipFunction(MF.getFunction())) {
> - initialize(MF);
> - }
> + if (skipFunction(MF.getFunction()))
> + return false;
> +
> + initialize(MF);
> return removeLD();
> }
> };
>
> diff --git a/llvm/test/CodeGen/BPF/optnone-1.ll b/llvm/test/CodeGen/BPF/optnone-1.ll
> new file mode 100644
> index 000000000000..b38e2630ff28
> --- /dev/null
> +++ b/llvm/test/CodeGen/BPF/optnone-1.ll
> @@ -0,0 +1,52 @@
> +; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
> +; Source Code:
> +; int test(int a, int b) { return a + b; }
> +; Compilation flag:
> +; clang -target bpf -g -S -emit-llvm test.c
> +
> +; Function Attrs: noinline nounwind optnone
> +define dso_local i32 @test(i32 %a, i32 %b) #0 !dbg !7 {
> +entry:
> + %a.addr = alloca i32, align 4
> + %b.addr = alloca i32, align 4
> + store i32 %a, i32* %a.addr, align 4
> + call void @llvm.dbg.declare(metadata i32* %a.addr, metadata !11, metadata !DIExpression()), !dbg !12
> + store i32 %b, i32* %b.addr, align 4
> + call void @llvm.dbg.declare(metadata i32* %b.addr, metadata !13, metadata !DIExpression()), !dbg !14
> + %0 = load i32, i32* %a.addr, align 4, !dbg !15
> + %1 = load i32, i32* %b.addr, align 4, !dbg !16
> + %add = add nsw i32 %0, %1, !dbg !17
> + ret i32 %add, !dbg !18
> +}
> +
> +; CHECK-LABEL: test
> +
> +; Function Attrs: nounwind readnone speculatable
> +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
> +
> +attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "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"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
> +attributes #1 = { nounwind readnone speculatable}
> +
> +!llvm.dbg.cu = !{!0}
> +!llvm.module.flags = !{!3, !4, !5}
> +!llvm.ident = !{!6}
> +
> +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 7f49dc496682e38335b204bbae371a0ca5057719)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
> +!1 = !DIFile(filename: "test.c", directory: "/tmp/home/yhs/work/tests/llvm")
> +!2 = !{}
> +!3 = !{i32 7, !"Dwarf Version", i32 4}
> +!4 = !{i32 2, !"Debug Info Version", i32 3}
> +!5 = !{i32 1, !"wchar_size", i32 4}
> +!6 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 7f49dc496682e38335b204bbae371a0ca5057719)"}
> +!7 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
> +!8 = !DISubroutineType(types: !9)
> +!9 = !{!10, !10, !10}
> +!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
> +!11 = !DILocalVariable(name: "a", arg: 1, scope: !7, file: !1, line: 1, type: !10)
> +!12 = !DILocation(line: 1, column: 14, scope: !7)
> +!13 = !DILocalVariable(name: "b", arg: 2, scope: !7, file: !1, line: 1, type: !10)
> +!14 = !DILocation(line: 1, column: 21, scope: !7)
> +!15 = !DILocation(line: 1, column: 33, scope: !7)
> +!16 = !DILocation(line: 1, column: 37, scope: !7)
> +!17 = !DILocation(line: 1, column: 35, scope: !7)
> +!18 = !DILocation(line: 1, column: 26, scope: !7)
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list