This is an archive of the discontinued LLVM Phabricator instance.

BPF: Workaround an InstCombine ICmp transformation with llvm.bpf.compare builtin
ClosedPublic

Authored by yonghong-song on Nov 1 2021, 9:16 AM.

Details

Summary

Commit acabad9ff6bf ("[InstCombine] try to canonicalize icmp with
trunc op into mask and cmp") added a transformation to
convert "(conv)a < power_2_const" to "a & <const>" in certain
cases and bpf kernel verifier has to handle the resulted code
conservatively and this may reject otherwise legitimate program.

This commit tries to prevent such a transformation. A bpf backend
builtin llvm.bpf.compare is added. The ICMP insn, which is subject to
above InstCombine transformation, is converted to the builtin
function. The builtin function is later lowered to original ICMP insn,
certainly after InstCombine pass.

With this change, all affected bpf strobemeta* selftests are
passed now.

Diff Detail

Event Timeline

yonghong-song created this revision.Nov 1 2021, 9:16 AM
yonghong-song requested review of this revision.Nov 1 2021, 9:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2021, 9:16 AM
ast accepted this revision.Nov 1 2021, 11:03 AM
This revision is now accepted and ready to land.Nov 1 2021, 11:03 AM
This revision was landed with ongoing or failed builds.Nov 1 2021, 2:54 PM
This revision was automatically updated to reflect the committed changes.