[PATCH] D134277: [RISCV][test] Combining comparison and logic ops. #17574

Ilya Andreev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 20 05:41:11 PDT 2022


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

Two comparison operations and a logical operation are combined into selection using MIN or MAX and comparison operation.
For optimization to be applied conditions have to be satisfied:

1. In comparison operations has to be the one common operand.
2. Comparation has to be the same with respect to common operand.
3. There are no more users of comparation except logic operation.
4. Every combination of comparation and AND, OR are supported.

It will convert

  %l0 = %a < %c
  %l1 = %b < %c
  %res = %l0 or %l1

into

  %sel = min(%a, %b)
  %res = %sel < %c

It supports several comparison operations (<, <=, >, >=), signed, unsigned, float, double values and different order of operands if they do not violate conditions.

[RISCV] Combining comparison and logic ops. #17574

Two comparison operations and a logical operation are combined into selection using MIN or MAX and comparison operation.
For optimization to be applied conditions have to be satisfied:

1. In comparison operations has to be the one common operand.
2. Comparation has to be the same with respect to common operand.
3. There are no more users of comparation except logic operation.
4. Every combination of comparation and AND, OR are supported.

It will convert

  %l0 = %a < %c
  %l1 = %b < %c
  %res = %l0 or %l1

into

  %sel = min(%a, %b)
  %res = %sel < %c

It supports several comparison operations (<, <=, >, >=), signed, unsigned, float, double values and different order of operands if they do not violate conditions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134277

Files:
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/test/CodeGen/RISCV/zbb-cmp-combine.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134277.461543.patch
Type: text/x-patch
Size: 18348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220920/076431c6/attachment.bin>


More information about the llvm-commits mailing list