BPF: Workaround InstCombine trunc+icmp => mask+icmp Optimization
authorYonghong Song <yhs@fb.com>
Fri, 19 Nov 2021 03:02:11 +0000 (19:02 -0800)
committerYonghong Song <yhs@fb.com>
Fri, 19 Nov 2021 04:25:28 +0000 (20:25 -0800)
commit8fb3f84484094230d563c1e4c1088755b7cde15b
treeec3509bd24b542d9da665845ba4da71169c10672
parent870dfa6b08d0304d4845491a15bd1bee711e6c52
BPF: Workaround InstCombine trunc+icmp => mask+icmp Optimization

Patch [1] added further InstCombine trunc+icmp => mask+icmp
optimization and this caused a couple of bpf selftest failure.
Previous llvm BPF backend patch [2] introduced llvm.bpf.compare
builtin to handle such situations.

This patch further added support ">" and ">=" icmp opcodes.
Tested with bpf selftests and all tests are passed including two
previously failed ones.

Note Patch [1] also added optimization if the to-be-compared
constant is negative-power-of-2 (-C) or not-of-power-of-2 (~C).
This patch didn't implement these two cases as typical bpf
program compares a scalar to a positive length or boundary value,
and this scalar later is used as a index into an array buffer
or packet buffer.

  [1] https://reviews.llvm.org/D112634
  [2] https://reviews.llvm.org/D112938

Differential Revision: https://reviews.llvm.org/D114215
llvm/lib/Target/BPF/BPFAdjustOpt.cpp
llvm/test/CodeGen/BPF/adjust-opt-icmp4.ll [new file with mode: 0644]