llvm-project/llvm/test
Jiong Wang ec51851026 bpf: fix wrong truncation elimination when there is back-edge/loop
Currently, BPF backend is doing truncation elimination. If one truncation
is performed on a value defined by narrow loads, then it could be redundant
given BPF loads zero extend the destination register implicitly.

When the definition of the truncated value is a merging value (PHI node)
that could come from different code paths, then checks need to be done on
all possible code paths.

Above described optimization was introduced as r306685, however it doesn't
work when there is back-edge, for example when loop is used inside BPF
code.

For example for the following code, a zero-extended value should be stored
into b[i], but the "and reg, 0xffff" is wrongly eliminated which then
generates corrupted data.

void cal1(unsigned short *a, unsigned long *b, unsigned int k)
{
  unsigned short e;

  e = *a;
  for (unsigned int i = 0; i < k; i++) {
    b[i] = e;
    e = ~e;
  }
}

The reason is r306685 was trying to do the PHI node checks inside isel
DAG2DAG phase, and the checks are done on MachineInstr. This is actually
wrong, because MachineInstr is being built during isel phase and the
associated information is not completed yet. A quick search shows none
target other than BPF is access MachineInstr info during isel phase.

For an PHI node, when you reached it during isel phase, it may have all
predecessors linked, but not successors. It seems successors are linked to
PHI node only when doing SelectionDAGISel::FinishBasicBlock and this
happens later than PreprocessISelDAG hook.

Previously, BPF program doesn't allow loop, there is probably the reason
why this bug was not exposed.

This patch therefore fixes the bug by the following approach:
 - The existing truncation elimination code and the associated
   "load_to_vreg_" records are removed.
 - Instead, implement truncation elimination using MachineSSA pass, this
   is where all information are built, and keep the pass together with other
   similar peephole optimizations inside BPFMIPeephole.cpp. Redundant move
   elimination logic is updated accordingly.
 - Unit testcase included + no compilation errors for kernel BPF selftest.

Patch Review
===
Patch was sent to and reviewed by BPF community at:

  https://lore.kernel.org/bpf

Reported-by: David Beckett <david.beckett@netronome.com>
Reviewed-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
llvm-svn: 375007
2019-10-16 15:27:59 +00:00
..
Analysis [MemorySSA] Update for partial unswitch. 2019-10-14 23:52:39 +00:00
Assembler [ThinLTO] Fix printing of NoInline function summary flag 2019-10-14 18:37:31 +00:00
Bindings [IRBuilder] Update IRBuilder::CreateFNeg(...) to return a UnaryOperator 2019-10-14 15:35:01 +00:00
Bitcode Add FMF to vector ops for phi 2019-10-14 17:39:32 +00:00
BugPoint
CodeGen bpf: fix wrong truncation elimination when there is back-edge/loop 2019-10-16 15:27:59 +00:00
DebugInfo [DebugInfo] Add a DW_OP_LLVM_entry_value operation 2019-10-15 11:31:21 +00:00
Demangle [Demangle] Add a few more options to the microsoft demangler 2019-10-15 08:29:56 +00:00
Examples
ExecutionEngine [JITLink] Switch to slab allocation for InProcessMemoryManager, re-enable test. 2019-10-15 21:06:57 +00:00
Feature [FPEnv] Add constrained intrinsics for lrint and lround 2019-10-07 13:20:00 +00:00
FileCheck [FileCheck] Implement --ignore-case option. 2019-10-11 11:59:14 +00:00
Instrumentation Insert module constructors in a module pass 2019-10-11 08:47:03 +00:00
Integer
JitListener
LTO Revert "Dead Virtual Function Elimination" 2019-10-14 23:25:25 +00:00
Linker
MC Added support for "#pragma clang section relro=<name>" 2019-10-15 18:31:10 +00:00
MachineVerifier Add an operand to memory intrinsics to denote the "tail" marker. 2019-09-28 05:33:21 +00:00
Object Reapply: [llvm-size] Tidy up error messages (PR42970) 2019-10-14 17:29:15 +00:00
ObjectYAML [yaml2obj/ObjectYAML] - Cleanup the error reporting API, add custom errors handlers. 2019-09-13 16:00:16 +00:00
Other Reapply r374743 with a fix for the ocaml binding 2019-10-14 16:15:14 +00:00
Reduce [Testing] Python 3 requires `print` to use parens 2019-09-20 13:52:47 +00:00
SafepointIRVerifier
Support
SymbolRewriter
TableGen [TableGen] Fix a bug that MCSchedClassDesc is interfered between different SchedModel 2019-10-11 08:36:54 +00:00
ThinLTO/X86 Revert "Dead Virtual Function Elimination" 2019-10-14 23:25:25 +00:00
Transforms [InstCombine][AMDGPU] Fix crash with v3i16/v3f16 buffer intrinsics 2019-10-16 11:14:01 +00:00
Unit
Verifier [DebugInfo] Add a DW_OP_LLVM_entry_value operation 2019-10-15 11:31:21 +00:00
YAMLParser
tools [llvm-ar] Make paths case insensitive when on windows 2019-10-16 14:07:57 +00:00
.clang-format
CMakeLists.txt
TestRunner.sh
lit.cfg.py Reland "[utils] Implement the llvm-locstats tool" 2019-10-02 07:00:01 +00:00
lit.site.cfg.py.in Follow-up to r372209: Use single quotes for host_ldflags in the lit config 2019-09-18 14:12:59 +00:00