1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-20 19:42:54 +02:00
llvm-mirror/lib/Target/BPF
Yonghong Song 473fd8d799 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
..
Disassembler Sort the remaining #include lines in include/... and lib/.... 2017-06-06 11:49:48 +00:00
InstPrinter Sort the remaining #include lines in include/... and lib/.... 2017-06-06 11:49:48 +00:00
MCTargetDesc Remove redundant argument. 2017-06-24 00:26:57 +00:00
TargetInfo Move the global variables representing each Target behind accessor function 2016-10-09 23:00:34 +00:00
BPF.h
BPF.td convert bpf assembler to look like kernel verifier output 2016-11-18 02:32:35 +00:00
BPFAsmPrinter.cpp bpf: clang-format on BPFAsmPrinter.cpp 2017-06-13 16:17:20 +00:00
BPFCallingConv.td
BPFFrameLowering.cpp
BPFFrameLowering.h Change eliminateCallFramePseudoInstr() to return an iterator 2016-03-31 18:33:38 +00:00
BPFInstrFormats.td
BPFInstrInfo.cpp Sort the remaining #include lines in include/... and lib/.... 2017-06-06 11:49:48 +00:00
BPFInstrInfo.h Finish renaming remaining analyzeBranch functions 2016-09-14 20:43:16 +00:00
BPFInstrInfo.td bpf: set missing types in insn tablegen file 2017-06-16 15:30:55 +00:00
BPFISelDAGToDAG.cpp bpf: remove unnecessary truncate operation 2017-06-29 15:18:54 +00:00
BPFISelLowering.cpp [bpf] disallow global_addr+off folding 2017-05-26 22:32:41 +00:00
BPFISelLowering.h [bpf] disallow global_addr+off folding 2017-05-26 22:32:41 +00:00
BPFMCInstLower.cpp Cleanup dump() functions. 2017-01-28 02:02:38 +00:00
BPFMCInstLower.h [bpf] error when unknown bpf helper is called 2017-01-17 07:26:17 +00:00
BPFRegisterInfo.cpp Sort the remaining #include lines in include/... and lib/.... 2017-06-06 11:49:48 +00:00
BPFRegisterInfo.h
BPFRegisterInfo.td
BPFSubtarget.cpp
BPFSubtarget.h
BPFTargetMachine.cpp Sort the remaining #include lines in include/... and lib/.... 2017-06-06 11:49:48 +00:00
BPFTargetMachine.h Delete Reloc::Default. 2016-05-18 22:04:49 +00:00
CMakeLists.txt [BPF] Correct the file name of the -gen-asm-matcher output file to not start with X86. 2017-05-31 19:01:05 +00:00
LLVMBuild.txt [bpf] add BPF disassembler 2016-11-20 02:25:00 +00:00