llvm-project/llvm/lib/Target/BPF
Yonghong Song 9276ef05c8 bpf: generate better lowering code for certain select/setcc instructions
Currently, for code like below,
===
  inner_map = bpf_map_lookup_elem(outer_map, &port_key);
  if (!inner_map) {
    inner_map = &fallback_map;
  }
===
the compiler generates (pseudo) code like the below:
===
  I1: r1 = bpf_map_lookup_elem(outer_map, &port_key);
  I2: r2 = 0
  I3: if (r1 == r2)
  I4:   r6 = &fallback_map
  I5: ...
===

During kernel verification process, After I1, r1 holds a state
map_ptr_or_null. If I3 condition is not taken
(path [I1, I2, I3, I5]), supposedly r1 should become map_ptr.
Unfortunately, kernel does not recognize this pattern
and r1 remains map_ptr_or_null at insn I5. This will cause
verificaiton failure later on.

Kernel, however, is able to recognize pattern "if (r1 == 0)"
properly and give a map_ptr state to r1 in the above case.

LLVM here generates suboptimal code which causes kernel verification
failure. This patch fixes the issue by changing BPF insn pattern
matching and lowering to generate proper codes if the righthand
parameter of the above condition is a constant. A test case
is also added.

Signed-off-by: Yonghong Song <yhs@fb.com>
llvm-svn: 308080
2017-07-15 05:41:42 +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 Fully fix the movw/movt addend. 2017-07-11 23:18:25 +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
BPFISelDAGToDAG.cpp bpf: remove unnecessary truncate operation 2017-06-29 15:18:54 +00:00
BPFISelLowering.cpp bpf: generate better lowering code for certain select/setcc instructions 2017-07-15 05:41:42 +00:00
BPFISelLowering.h [bpf] disallow global_addr+off folding 2017-05-26 22:32:41 +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: generate better lowering code for certain select/setcc instructions 2017-07-15 05:41:42 +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