llvm-project/llvm/test/CodeGen/BPF
Yonghong Song 5fbe01b12d bpf: remove unnecessary truncate operation
For networking-type bpf program, it often needs to access
packet data. A context data structure is provided to the bpf
programs with two fields:
        u32 data;
        u32 data_end;
User can access these two fields with ctx->data and ctx->data_end.
During program verification process, the kernel verifier modifies
the bpf program with loading of actual pointer value from kernel
data structure.
    r = ctx->data      ===> r = actual data start ptr
    r = ctx->data_end  ===> r = actual data end ptr

A typical program accessing ctx->data like
    char *data_ptr = (char *)(long)ctx->data
will result in a 32-bit load followed by a zero extension.
Such an operation is combined into a single LDW in DAG combiner
as bpf LDW does zero extension automatically.

In cases like the below (which can be a result of global value numbering
and partial redundancy elimination before insn selection):
B1:
   u32 a = load-32-bit &ctx->data
   u64 pa = zext a
   ...
B2:
   u32 b = load-32-bit &ctx->data
   u64 pb = zext b
   ...
B3:
   u32 m = PHI(a, b)
   u64 pm = zext m

In B3, "pm = zext m" cannot be removed, which although is legal
from compiler perspective, will generate incorrect code after
kernel verification.

This patch recognizes this pattern and traces through PHI node
to see whether the operand of "zext m" is defined with LDWs or not.
If it is, the "zext m" itself can be removed.

The patch also recognizes the pattern where the load and use of
the load value not in the same basic block, where truncate operation
may be removed as well.

The patch handles 1-byte, 2-byte and 4-byte truncation.

Two test cases are added to verify the transformation happens properly
for the above code pattern.

Signed-off-by: Yonghong Song <yhs@fb.com>
llvm-svn: 306685
2017-06-29 15:18:54 +00:00
..
alu8.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
atomics.ll [bpf] add BPF disassembler 2016-11-20 02:25:00 +00:00
basictest.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
byval.ll
cc_args.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
cc_args_be.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
cc_ret.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
cmp.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
dwarfdump.ll [bpf] fix a bug which causes incorrect big endian reloc fixup 2017-05-05 18:05:00 +00:00
ex1.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
fi_ri.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
intrinsics.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
lit.local.cfg
load.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
loops.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
many_args1.ll
many_args2.ll
mem_offset.ll [bpf] Fix memory offset check for loads and stores 2017-04-13 22:24:13 +00:00
mem_offset_be.ll [bpf] add bigendian support to disassembler 2017-04-28 16:51:01 +00:00
objdump_atomics.ll [bpf] add BPF disassembler 2016-11-20 02:25:00 +00:00
objdump_intrinsics.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
objdump_trivial.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
reloc.ll [bpf] add relocation support 2017-05-03 17:30:56 +00:00
remove_truncate_1.ll bpf: remove unnecessary truncate operation 2017-06-29 15:18:54 +00:00
remove_truncate_2.ll bpf: remove unnecessary truncate operation 2017-06-29 15:18:54 +00:00
rodata_1.ll bpf: avoid load from read-only sections 2017-06-16 15:41:16 +00:00
rodata_2.ll bpf: avoid load from read-only sections 2017-06-16 15:41:16 +00:00
rodata_3.ll bpf: avoid load from read-only sections 2017-06-16 15:41:16 +00:00
rodata_4.ll bpf: avoid load from read-only sections 2017-06-16 15:41:16 +00:00
sanity.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
sdiv_error.ll
setcc.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
shifts.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
sockex2.ll convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
struct_ret1.ll
struct_ret2.ll
undef.ll In visitSTORE, always use FindBetterChain, rather than only when UseAA is enabled. 2017-03-14 00:34:14 +00:00
vararg1.ll
warn-call.ll [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
warn-stack.ll Add address space mangling to lifetime intrinsics 2017-04-10 20:18:21 +00:00