[PATCH] D131482: [RISCV] Return true in hasBitTest for Zbs and add new BINVI pattern for resulting canonicalisation

Alex Bradbury via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 9 03:49:52 PDT 2022


asb created this revision.
asb added reviewers: craig.topper, reames.
Herald added subscribers: wingo, sunshaoce, pmatos, VincentWu, luke957, StephenFan, vkmr, frasercrmck, evandro, luismarques, apazos, sameer.abuasal, steven.zhang, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
asb requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.

As the Zbs extension include bext[i] and binv[i] for bit extract / invert, we can unconditionally return true from this hook when Zbs is present. This hook causes the DAG combiner to perform the following canonicalisation:

  and (not (srl X, C)), 1 --> (and X, 1<<C) == 0
  and (srl (not X), C)), 1 --> (and X, 1<<C) == 0

As changing the hook on its own causes a codegen regression, this patch also adds a new BINVI pattern to match this canonicalised form.

I'll note that the doc comment for hasBitTest indicates hasBitTest will be used for `(X & (1 << Y)) ==/!= 0`, but the use of the hook in the DAGCombiner only canonicalises the `==0` form (BINVI).


https://reviews.llvm.org/D131482

Files:
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
  llvm/test/CodeGen/RISCV/bittest.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131482.451092.patch
Type: text/x-patch
Size: 6949 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220809/c934becf/attachment.bin>


More information about the llvm-commits mailing list