[PATCH] D71860: AMDGPU/GlobalISel: Replace handling of boolean values

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 24 12:55:31 PST 2019


arsenm created this revision.
arsenm added reviewers: dsanders, tstellar, nhaehnle, kerbowa.
Herald added subscribers: Petar.Avramovic, hiraditya, t-tye, tpr, dstuttard, rovka, yaxunl, wdng, jvesely, kzhuravl.
Herald added a project: LLVM.
arsenm added a parent revision: D70300: GlobalISel: Add type argument to getRegBankFromRegClass.

This solves selection failures with generated selection patterns,
which would fail due to inferring the SGPR reg bank for virtual
registers with a set register class instead of VCC bank. Use
instruction selection would constrain the virtual register to a
specific class, so when the def was selected later the bank no longer
was set to VCC.

      

Remove the SCC reg bank. SCC isn't directly addressable, so it
requires copying from SCC to an allocatable 32-bit register during
selection, so these might as well be treated as 32-bit SGPR values.

Now any scalar boolean value that will produce an outupt in SCC should
be widened during RegBankSelect to s32. Any s1 value should be a
vector boolean during selection. This makes the vcc register bank
unambiguous with a normal SGPR during selection.

      

Summary of how this should now work:

      

- G_TRUNC is always a no-op, and never should use a vcc bank result.

- SALU boolean operations should be promoted to s32 in RegBankSelect apply mapping

- An s1 value means vcc bank at selection. The exception is for legalization artifacts that use s1, which are never VCC. All other contexts should infer the VCC register classes for s1 typed registers. The LLT for the register is now needed to infer the correct register class. Extensions with vcc sources should be legalized to a select of constants during RegBankSelect.

- Copy from non-vcc to vcc ensures high bits of the input value are cleared during selection.
  - SALU boolean inputs should ensure the inputs are 0/1. This includes select, conditional branches, and carry-ins.

There are a few somewhat dirty details. One is that G_TRUNC/G_*EXT
selection ignores the usual register-bank from register class
functions, and can't handle truncates with VCC result banks. I think
this is OK, since the artifacts are specially treated anyway. This
does require some care to avoid producing cases with vcc. There will
also be no 100% reliable way to verify this rule is followed in
selection in case of register classes, and violations manifests
themselves as invalid copy instructions much later.

      

Standard phi handling also only considers the bank of the result
register, and doesn't insert copies to make the source banks
match. This doesn't work for vcc, so we have to manually correct phi
inputs in this case. We should add a verifier check to make sure there
are no phis with mixed vcc and non-vcc register bank inputs.

      

There's also some duplication with the LegalizerHelper, and some code
which should live in the helper. I don't see a good way to share
special knowledge about what types to use for intermediate operations
depending on the bank for example. Using the helper to replace
extensions with selects also seems somewhat awkward to me.

      

Another issue is there are some contexts calling
getRegBankFromRegClass that apparently don't have the LLT type for the
register, but I haven't yet run into a real issue from this.

This also introduces new unnecessary instructions in most cases, since
we don't yet try to optimize out the zext when the source is known to
come from a compare.


https://reviews.llvm.org/D71860

Files:
  llvm/lib/Target/AMDGPU/AMDGPUGenRegisterBankInfo.def
  llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.cpp
  llvm/lib/Target/AMDGPU/AMDGPUInstructionSelector.h
  llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp
  llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
  llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.h
  llvm/lib/Target/AMDGPU/AMDGPURegisterBanks.td
  llvm/lib/Target/AMDGPU/SIRegisterInfo.cpp
  llvm/test/CodeGen/AMDGPU/GlobalISel/bool-legalization.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-and.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-anyext.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-brcond.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-copy.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-fcmp.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-icmp.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-icmp.s64.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-implicit-def.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-or.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-phi-invalid.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-phi.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-select.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-sext.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-trunc.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-uaddo.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-usubo.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-xor.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/inst-select-zext.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/legalize-brcond.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.end.cf.i32.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.end.cf.i64.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.if.break.i32.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.if.break.i64.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.is.private.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/llvm.amdgcn.is.shared.ll
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.div.fmas.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.kill.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-amdgcn.wqm.vote.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-and-s1.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-anyext.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-brcond.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-icmp.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-or.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-phi-s1.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-phi.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-sadde.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-select.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-sext.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-smax.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-smin.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-ssube.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-trunc.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-uadde.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-uaddo.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-umax.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-umin.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-usube.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-usubo.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-xor.mir
  llvm/test/CodeGen/AMDGPU/GlobalISel/regbankselect-zext.mir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71860.235233.patch
Type: text/x-patch
Size: 448343 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191224/7a3e0ccd/attachment-0001.bin>


More information about the llvm-commits mailing list