[PATCH] D96596: [AArch64] Convert CMP/SELECT sign patterns to OR & ASR.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 12 05:47:49 PST 2021


fhahn created this revision.
fhahn added reviewers: SjoerdMeijer, dmgreen, aemerson, t.p.northover.
Herald added subscribers: danielkiss, hiraditya, kristof.beyls.
fhahn requested review of this revision.
Herald added a project: LLVM.

ICMP & SELECT patterns extracting the sign of a value can be simplified
to OR & ASR (see  https://alive2.llvm.org/ce/z/Xx4iZ0).

This does not save any instructions in IR, but it is profitable on
AArch64, because we need at least 2 extra instructions to materialize 1
and -1 for the SELECT.

The improvements result in ~5% speedups on loops of the form

  static int sign_of(int x) {
    if (x < 0) return -1;
    return 1;
  }
  
  void foo(const int *x, int *res, int cnt) {
    for (int i=0;i<cnt;i++)
      res[i] = sign_of(x[i]);
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96596

Files:
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/test/CodeGen/AArch64/cmp-select-sign.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96596.323299.patch
Type: text/x-patch
Size: 12924 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210212/8053ed1b/attachment.bin>


More information about the llvm-commits mailing list