[PATCH] D123883: [BPF] Fix a bug in BPFMISimplifyPatchable pass

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 15 16:16:16 PDT 2022


yonghong-song created this revision.
yonghong-song added a reviewer: ast.
Herald added a subscriber: hiraditya.
Herald added a project: All.
yonghong-song requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

LLVM BPF pass SimplifyPatchable is used to do necessary
code conversion for CO-RE operations. When studying bpf
selftest 'exhandler', I found a corner case not handled properly.
The following is the C code, modified from original 'exhandler'
code.

  int g;
  int test(struct t1 *p) {
    struct t2 *q = p->q;
    if (q)
      return 0;
    struct t3 *f = q->f;
    if (!f) g = 5;
    return 0;
  }

For code:

  struct t3 *f = q->f;
  if (!f) ...

The IR before BPFMISimplifyPatchable pass looks like:

  %5:gpr = LD_imm64 @"llvm.t2:0:8$0:1"
  %6:gpr = LDD killed %5:gpr, 0
  %7:gpr = LDD killed %6:gpr, 0
  JNE_ri killed %7:gpr, 0, %bb.3
  JMP %bb.2

Note that compiler knows q = 0 based dataflow and value analysis.
The correct generated code after the pass should be

  %5:gpr = LD_imm64 @"llvm.t2:0:8$0:1"
  %7:gpr = LDD killed %5:gpr, 0
  JNE_ri killed %7:gpr, 0, %bb.3
  JMP %bb.2

But the current implementation did further optimization for the
above code and generates

  %5:gpr = LD_imm64 @"llvm.t2:0:8$0:1"
  JNE_ri killed %5:gpr, 0, %bb.3
  JMP %bb.2

which is incorrect.

This patch added a cache to remember those load insns not associated
with CO-RE offset value and will skip these load insns during
transformation.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123883

Files:
  llvm/lib/Target/BPF/BPFMISimplifyPatchable.cpp
  llvm/test/CodeGen/BPF/CORE/simplifypatable-nullptr.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123883.423186.patch
Type: text/x-patch
Size: 8489 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220415/2da25a27/attachment-0001.bin>


More information about the llvm-commits mailing list