[BPF] disable ReduceLoadWidth during SelectionDag phase
authorYonghong Song <yhs@fb.com>
Tue, 4 Feb 2020 19:21:54 +0000 (11:21 -0800)
committerYonghong Song <yhs@fb.com>
Wed, 5 Feb 2020 02:37:43 +0000 (18:37 -0800)
commitd96c1bbaa03574daf759e5e9a6c75047c5e3af64
treede01f4b403c8a28fa7240ff81758a6ead2150a7b
parent57c54ddd7f9857d9054a1e163799eb5235c89602
[BPF] disable ReduceLoadWidth during SelectionDag phase

The compiler may transform the following code
  ctx = ctx + reloc_offset
  ... (*(u32 *)ctx) & 0x8000 ...
to
  ctx = ctx + reloc_offset
  ... (*(u8 *)(ctx + 1)) & 0x80 ...
where reloc_offset will be replaced with a constant during
AsmPrinter phase.

The above transformed code will be rejected the kernel verifier
as it does not allow
  *(type *)((ctx + non_zero_offset1) + non_zero_offset2)
style access pattern.

It is hard at SelectionDag phase to identify whether a load
is related to context or not. Sometime, interprocedure analysis
may be needed. So let us simply prevent such optimization
from happening.

Differential Revision: https://reviews.llvm.org/D73997
llvm/lib/Target/BPF/BPFISelLowering.h
llvm/test/CodeGen/BPF/CORE/no-narrow-load.ll [new file with mode: 0644]