[PATCH] D72787: [BPF] Adjust optimizations to generate kernel verifier friendly codes

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 15 10:12:56 PST 2020


yonghong-song created this revision.
yonghong-song added a reviewer: ast.
Herald added subscribers: llvm-commits, hiraditya, mgorny.
Herald added a project: LLVM.
yonghong-song added a comment.

The current kernel did not handle signed compare well for 32bit registers. I will need to make that change first in order to make this llvm change effective.


The InstCmbine phase did the following optimization:

  V >= Lo && V <  Hi --> V - Lo u<  Hi - Lo
  V <  Lo || V >= Hi --> V - Lo u>= Hi - Lo

This generates code like below:

  V.off  = V - Lo
  ConstV = Hi - Lo
  Cond = V.off u< ConstV
  if (Cond) ... 
  ... V is used ... 

The current linux verifier is not able to handle such a sequence
and may reject the prog as it did not used refined value range
for V at the place of "V is used".

Previous attempt, https://reviews.llvm.org/D70372, is to disable
this optimization under BPF target. But it violates the principle
that InstCombiner is target independent.

So here, an IR pass is implemented trying to undo this optimization.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72787

Files:
  llvm/lib/Target/BPF/BPF.h
  llvm/lib/Target/BPF/BPFAdjustOpt.cpp
  llvm/lib/Target/BPF/BPFTargetMachine.cpp
  llvm/lib/Target/BPF/CMakeLists.txt
  llvm/test/CodeGen/BPF/adjust-instcombine-1.ll
  llvm/test/CodeGen/BPF/adjust-instcombine-2.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72787.238309.patch
Type: text/x-patch
Size: 12582 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200115/c668a6a7/attachment.bin>


More information about the llvm-commits mailing list