From a0332bee4fdd78ff6513f83b4210a2b808d08c7c Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Mon, 20 Nov 2017 21:37:58 +0000 Subject: [PATCH] bpf: add a test case for trunc-op optimization Commit b5cbc7760ab8 ("[bpf] allow direct and indirect calls") allowed more than one function in the bpf program, and commit 114353884415 ("bpf: fix a bug in trunc-op optimization") fixed a bug in trunc-op optimization which only showed up with more than one function in the bpf program. This patch added a test case for trunc-op optimization for bpf programs with two functions. Reverting commit "bpf: fix a bug in trunc-op optimization" will cause failure for this test case. Signed-off-by: Yonghong Song git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318695 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CodeGen/BPF/remove_truncate_3.ll | 106 ++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 test/CodeGen/BPF/remove_truncate_3.ll diff --git a/test/CodeGen/BPF/remove_truncate_3.ll b/test/CodeGen/BPF/remove_truncate_3.ll new file mode 100644 index 00000000000..4e58b5e2d07 --- /dev/null +++ b/test/CodeGen/BPF/remove_truncate_3.ll @@ -0,0 +1,106 @@ +; RUN: llc < %s -march=bpf -verify-machineinstrs | FileCheck %s + +; Source code: +; struct xdp_md { +; unsigned data; +; unsigned data_end; +; }; +; +; int gbl; +; int xdp_dummy(struct xdp_md *xdp) +; { +; char tmp; +; long addr; +; +; if (gbl) { +; long addr1 = (long)xdp->data; +; tmp = *(char *)addr1; +; if (tmp == 1) +; return 3; +; } else { +; tmp = *(volatile char *)(long)xdp->data_end; +; if (tmp == 1) +; return 2; +; } +; addr = (long)xdp->data; +; tmp = *(volatile char *)addr; +; if (tmp == 0) +; return 1; +; return 0; +; } +; +; unsigned int rol32(unsigned int word, unsigned int shift) +; { +; return (word << shift) | (word >> ((-shift) & 31)); +; } +%struct.xdp_md = type { i32, i32 } + +@gbl = common local_unnamed_addr global i32 0, align 4 + +; Function Attrs: norecurse nounwind +define i32 @xdp_dummy(%struct.xdp_md* nocapture readonly) local_unnamed_addr #0 { + %2 = load i32, i32* @gbl, align 4 + %3 = icmp eq i32 %2, 0 + br i1 %3, label %11, label %4 + +;