1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-24 05:23:45 +02:00
Go to file
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
bindings [NFC] Remove multiple semicolons 2017-06-28 23:15:16 +00:00
cmake TableGen.cmake: Use DEPFILE for Ninja Generator with CMake>=3.7. 2017-06-21 22:04:07 +00:00
docs fix various typos 2017-06-26 02:45:39 +00:00
examples [ORC] Re-apply r306166 and r306168 with fix for regression test. 2017-06-23 23:25:28 +00:00
include Revert "r306529 - [X86] Correct dwarf unwind information in function epilogue" 2017-06-29 13:58:24 +00:00
lib bpf: remove unnecessary truncate operation 2017-06-29 15:18:54 +00:00
projects Add temporary workaround to allow in-tree libc++ builds on Windows 2017-05-11 01:44:30 +00:00
resources In MSVC builds embed a VERSIONINFO resource in our exe and DLL files. 2015-06-12 15:58:29 +00:00
runtimes [CMake][runtimes] Add install target for runtimes builtins 2017-06-02 19:38:11 +00:00
test bpf: remove unnecessary truncate operation 2017-06-29 15:18:54 +00:00
tools [NFC] Remove multiple semicolons 2017-06-28 23:15:16 +00:00
unittests Recommit "[Support] Add RetryAfterSignal helper function" 2017-06-29 13:15:31 +00:00
utils [lit] Re-apply: Fix some convoluted logic around Unicode encoding, and de-duplicate across modules that used it. 2017-06-29 04:37:35 +00:00
.arcconfig project_id is from another era in phabricator land and does not provide any value. 2016-09-27 15:47:29 +00:00
.clang-format Test commit. 2014-03-02 13:08:46 +00:00
.clang-tidy .clang-tidy: correct style name is 'camelBack' not 'lowerCase'. 2016-09-13 19:04:26 +00:00
.gitignore gitignore: Ignore .vs folder (VS2017 config files) 2017-04-08 00:16:58 +00:00
CMakeLists.txt [Solaris] replace Solaris.h hack with a set of better hacks 2017-06-22 13:18:46 +00:00
CODE_OWNERS.TXT [CODE_OWNERS] Add my other email address since my commits are now using my work email. 2017-06-24 03:26:01 +00:00
configure Remove autoconf support 2016-01-26 21:29:08 +00:00
CREDITS.TXT Another test commit 2017-06-24 21:04:32 +00:00
LICENSE.TXT Bump year to 2017 in LICENSE.txt 2017-01-12 18:02:42 +00:00
llvm.spec.in [Sparc] Implement i64 load/store support for 32-bit sparc. 2015-08-10 19:11:39 +00:00
LLVMBuild.txt
README.txt Test commit. Added a blank line. 2017-03-06 20:45:33 +00:00
RELEASE_TESTERS.TXT Update the release tester for MIPS. NFC. 2017-01-17 11:00:28 +00:00

Low Level Virtual Machine (LLVM)
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.