diff options
author | Peter Klausler <pklausler@nvidia.com> | 2022-04-04 11:39:51 -0700 |
---|---|---|
committer | Yonghong Song <yhs@fb.com> | 2022-04-19 15:24:26 -0700 |
commit | 497a5f04159472914a99ab9ac7b85a708069b40e (patch) | |
tree | b5f096b7fbc7a8796f2e5a38ed5ce6300174c12b /llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | |
parent | 6b0bed7ea563624622c3c1fb1a3c90cd32c78db6 (diff) | |
download | llvm-497a5f04159472914a99ab9ac7b85a708069b40e.zip llvm-497a5f04159472914a99ab9ac7b85a708069b40e.tar.gz llvm-497a5f04159472914a99ab9ac7b85a708069b40e.tar.bz2 |
[BPF] Fix a bug in BPFMISimplifyPatchable pass
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.
Differential Revision: https://reviews.llvm.org/D123883
Diffstat (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp')
0 files changed, 0 insertions, 0 deletions