[PATCH] D48537: AMDGPU: Add pass to lower kernel arguments to loads

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 25 02:17:01 PDT 2018


arsenm created this revision.
arsenm added reviewers: tstellar, rampitec.
Herald added subscribers: kristof.beyls, t-tye, tpr, dstuttard, mehdi_amini, yaxunl, mgorny, nhaehnle, wdng, kzhuravl, qcolombet.
Herald added a reviewer: javed.absar.

This replaces most argument uses with loads, but for
now not all.

      

The code in SelectionDAG for calling convention lowering
is actively harmful for amdgpu_kernel. It attempts to
split the argument types into register legal types, which
results in low quality code for arbitary types. Since
all kernel arguments are passed in memory, we just want the
raw types.

      

I've tried a couple of methods of mitigating this in SelectionDAG,
but it's easier to just bypass this problem alltogether. It's
possible to hack around the problem in the initial lowering,
but the real problem is the DAG then expects to be able to use
CopyToReg/CopyFromReg for uses of the arguments outside the block.

      

Exposing the argument loads in the IR also has the advantage
that the LoadStoreVectorizer can merge them.

      

I'm not sure the best approach to dealing with the IR
argument list is. The patch as-is just leaves the IR arguments
in place, so all the existing code will still compute the same
kernarg size and pointlessly lowers the arguments.

      

Arguably the frontend should emit kernels with an empty argument
list in the first place. Alternatively a dummy array could be
inserted as a single argument just to reserve space.

      

This does have some disadvantages. Local pointer kernel arguments can
no longer have AssertZext placed  on them as the equivalent !range
metadata is not valid on pointer  typed loads. This is mostly bad
for SI which needs to know about the known bits in order to use the
DS instruction offset, so in this case this is not done.

      

More importantly, this skips noalias arguments since this pass
does not yet convert this to the equivalent !alias.scope and !noalias
metadata. Producing this metadata correctly seems to be tricky,
although this logically is the same as inlining into a function which
doesn't exist. Additionally, exposing these loads to the vectorizer
may result in degraded aliasing information if a pointer load is
merged with another argument load.

      

I'm also not entirely sure this is preserving the current clover
ABI, although I would greatly prefer if it would stop widening
arguments and match the HSA ABI. As-is I think it is extending
< 4-byte arguments to 4-bytes but doesn't align them to 4-bytes.


https://reviews.llvm.org/D48537

Files:
  lib/Target/AMDGPU/AMDGPU.h
  lib/Target/AMDGPU/AMDGPULowerKernelArguments.cpp
  lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
  lib/Target/AMDGPU/CMakeLists.txt
  test/CodeGen/AMDGPU/GlobalISel/smrd.ll
  test/CodeGen/AMDGPU/add_i64.ll
  test/CodeGen/AMDGPU/amdhsa-trap-num-sgprs.ll
  test/CodeGen/AMDGPU/and.ll
  test/CodeGen/AMDGPU/ashr.v2i16.ll
  test/CodeGen/AMDGPU/atomic_cmp_swap_local.ll
  test/CodeGen/AMDGPU/attr-amdgpu-num-sgpr-spill-to-smem.ll
  test/CodeGen/AMDGPU/attr-amdgpu-num-sgpr.ll
  test/CodeGen/AMDGPU/basic-branch.ll
  test/CodeGen/AMDGPU/bfe-patterns.ll
  test/CodeGen/AMDGPU/bfi_int.ll
  test/CodeGen/AMDGPU/br_cc.f16.ll
  test/CodeGen/AMDGPU/branch-relaxation.ll
  test/CodeGen/AMDGPU/code-object-v3.ll
  test/CodeGen/AMDGPU/ctlz.ll
  test/CodeGen/AMDGPU/ctlz_zero_undef.ll
  test/CodeGen/AMDGPU/ctpop.ll
  test/CodeGen/AMDGPU/ctpop16.ll
  test/CodeGen/AMDGPU/ctpop64.ll
  test/CodeGen/AMDGPU/extract_vector_elt-f16.ll
  test/CodeGen/AMDGPU/extract_vector_elt-i16.ll
  test/CodeGen/AMDGPU/extract_vector_elt-i8.ll
  test/CodeGen/AMDGPU/fabs.f16.ll
  test/CodeGen/AMDGPU/fabs.f64.ll
  test/CodeGen/AMDGPU/fabs.ll
  test/CodeGen/AMDGPU/fadd.f16.ll
  test/CodeGen/AMDGPU/fcmp.f16.ll
  test/CodeGen/AMDGPU/fcopysign.f16.ll
  test/CodeGen/AMDGPU/fcopysign.f32.ll
  test/CodeGen/AMDGPU/fcopysign.f64.ll
  test/CodeGen/AMDGPU/fma.ll
  test/CodeGen/AMDGPU/fmin_legacy.ll
  test/CodeGen/AMDGPU/fmul-2-combine-multi-use.ll
  test/CodeGen/AMDGPU/fmul.f16.ll
  test/CodeGen/AMDGPU/fneg-fabs.f16.ll
  test/CodeGen/AMDGPU/fneg-fabs.f64.ll
  test/CodeGen/AMDGPU/fneg-fabs.ll
  test/CodeGen/AMDGPU/fneg.f64.ll
  test/CodeGen/AMDGPU/frame-index-amdgiz.ll
  test/CodeGen/AMDGPU/fsub.f16.ll
  test/CodeGen/AMDGPU/global_smrd.ll
  test/CodeGen/AMDGPU/half.ll
  test/CodeGen/AMDGPU/hsa-metadata-kernel-code-props.ll
  test/CodeGen/AMDGPU/imm.ll
  test/CodeGen/AMDGPU/immv216.ll
  test/CodeGen/AMDGPU/insert_vector_elt.ll
  test/CodeGen/AMDGPU/insert_vector_elt.v2i16.ll
  test/CodeGen/AMDGPU/kernel-args.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.buffer.store.format.d16.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.class.f16.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.class.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.cvt.pk.i16.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.cvt.pk.u16.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.cvt.pknorm.i16.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.cvt.pknorm.u16.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.cvt.pkrtz.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.div.fixup.f16.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.div.fixup.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.div.fmas.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.div.scale.ll
  test/CodeGen/AMDGPU/llvm.amdgcn.tbuffer.store.d16.ll
  test/CodeGen/AMDGPU/llvm.ceil.f16.ll
  test/CodeGen/AMDGPU/llvm.cos.f16.ll
  test/CodeGen/AMDGPU/llvm.dbg.value.ll
  test/CodeGen/AMDGPU/llvm.floor.f16.ll
  test/CodeGen/AMDGPU/llvm.fma.f16.ll
  test/CodeGen/AMDGPU/llvm.fmuladd.f16.ll
  test/CodeGen/AMDGPU/llvm.maxnum.f16.ll
  test/CodeGen/AMDGPU/llvm.minnum.f16.ll
  test/CodeGen/AMDGPU/llvm.rint.f16.ll
  test/CodeGen/AMDGPU/llvm.sin.f16.ll
  test/CodeGen/AMDGPU/llvm.trunc.f16.ll
  test/CodeGen/AMDGPU/load-select-ptr.ll
  test/CodeGen/AMDGPU/lower-kernargs.ll
  test/CodeGen/AMDGPU/lshr.v2i16.ll
  test/CodeGen/AMDGPU/madak.ll
  test/CodeGen/AMDGPU/madmk.ll
  test/CodeGen/AMDGPU/max.ll
  test/CodeGen/AMDGPU/min.ll
  test/CodeGen/AMDGPU/missing-store.ll
  test/CodeGen/AMDGPU/move-addr64-rsrc-dead-subreg-writes.ll
  test/CodeGen/AMDGPU/mul.i16.ll
  test/CodeGen/AMDGPU/mul.ll
  test/CodeGen/AMDGPU/mul_int24.ll
  test/CodeGen/AMDGPU/mul_uint24-amdgcn.ll
  test/CodeGen/AMDGPU/multi-divergent-exit-region.ll
  test/CodeGen/AMDGPU/no-shrink-extloads.ll
  test/CodeGen/AMDGPU/not-scalarize-volatile-load.ll
  test/CodeGen/AMDGPU/operand-spacing.ll
  test/CodeGen/AMDGPU/or.ll
  test/CodeGen/AMDGPU/partial-sgpr-to-vgpr-spills.ll
  test/CodeGen/AMDGPU/reduce-store-width-alignment.ll
  test/CodeGen/AMDGPU/sad.ll
  test/CodeGen/AMDGPU/schedule-kernel-arg-loads.ll
  test/CodeGen/AMDGPU/schedule-regpressure-limit2.ll
  test/CodeGen/AMDGPU/select-i1.ll
  test/CodeGen/AMDGPU/select-opt.ll
  test/CodeGen/AMDGPU/select.f16.ll
  test/CodeGen/AMDGPU/setcc-opt.ll
  test/CodeGen/AMDGPU/sgpr-control-flow.ll
  test/CodeGen/AMDGPU/shl.ll
  test/CodeGen/AMDGPU/shl.v2i16.ll
  test/CodeGen/AMDGPU/shl_add_constant.ll
  test/CodeGen/AMDGPU/sign_extend.ll
  test/CodeGen/AMDGPU/smed3.ll
  test/CodeGen/AMDGPU/sminmax.ll
  test/CodeGen/AMDGPU/sminmax.v2i16.ll
  test/CodeGen/AMDGPU/smrd.ll
  test/CodeGen/AMDGPU/sra.ll
  test/CodeGen/AMDGPU/srl.ll
  test/CodeGen/AMDGPU/store-weird-sizes.ll
  test/CodeGen/AMDGPU/sub.ll
  test/CodeGen/AMDGPU/subreg-coalescer-undef-use.ll
  test/CodeGen/AMDGPU/trunc-store-i1.ll
  test/CodeGen/AMDGPU/trunc.ll
  test/CodeGen/AMDGPU/udivrem.ll
  test/CodeGen/AMDGPU/umed3.ll
  test/CodeGen/AMDGPU/unaligned-load-store.ll
  test/CodeGen/AMDGPU/uniform-cfg.ll
  test/CodeGen/AMDGPU/use-sgpr-multiple-times.ll
  test/CodeGen/AMDGPU/v_cndmask.ll
  test/CodeGen/AMDGPU/v_mac_f16.ll
  test/CodeGen/AMDGPU/v_madak_f16.ll
  test/CodeGen/AMDGPU/xor.ll
  test/CodeGen/AMDGPU/zero_extend.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48537.152641.patch
Type: text/x-patch
Size: 420792 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180625/0be2b5b8/attachment-0001.bin>


More information about the llvm-commits mailing list