[PATCH] D148551: [RFC][TTI][BPF] Ensure ArgumentPromotion Not Exceeding Target MaxArgs

Yonghong Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 11:27:22 PDT 2023


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

With LLVM patch https://reviews.llvm.org/D148269, we hit a linux kernel
bpf selftest compilation failure like below:

  ... 
  progs/test_xdp_noinline.c:739:8: error: too many args to t8: i64 = GlobalAddress<ptr @encap_v4> 0, progs/test_xdp_noinline.c:739:8
              if (!encap_v4(xdp, cval, &pckt, dst, pkt_bytes))
                   ^   
  ... 
  progs/test_xdp_noinline.c:321:6: error: defined with too many args
  bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
       ^   
  ... 

Note that bpf selftests are compiled with -O2 which is
the recommended flag for bpf community.

The bpf backend calling convention is only allowing 5
parameters in registers and does not allow pass arguments
through stacks. In the above case, ArgumentPromotionPass
replaced parameter '&pckt' as two parameters, so the total
number of arguments after ArgumentPromotion pass becomes 6
and this caused later compilation failure during instruction
selection phase.

This patch added a TargetTransformInfo hook getMaxNumArgs()
which returns 5 for BPF and UINT_MAX for other targets.

The patch is incomplete:

- Need to add some tests to trigger ArgumentPromotion with BPF target
- getMaxNumArgs() does not really cover all cases. For example, one function has 4 arguments and one of them is 16byte struct value, so at register level, all 5 registers are already occupied. In this case, if one of ptr arguments is promoted into 2, it will cause eventual compilation failure during isel phase although it succeeded in ArgumentPromotion checking. Should we really address such scenario with TTI hook to inspect all arguments?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148551

Files:
  llvm/include/llvm/Analysis/TargetTransformInfo.h
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/lib/Analysis/TargetTransformInfo.cpp
  llvm/lib/Target/BPF/BPFTargetTransformInfo.h
  llvm/lib/Transforms/IPO/ArgumentPromotion.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148551.514333.patch
Type: text/x-patch
Size: 3480 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230417/3da29fe7/attachment.bin>


More information about the llvm-commits mailing list