[AArch64] Convert CMP/SELECT sign patterns to OR & ASR.
authorFlorian Hahn <flo@fhahn.com>
Tue, 16 Feb 2021 17:12:30 +0000 (17:12 +0000)
committerFlorian Hahn <flo@fhahn.com>
Tue, 16 Feb 2021 17:17:34 +0000 (17:17 +0000)
commit211147c5ba49a17c8624186f50519885d89ca33d
treefbc5cbe90a66a10050142d39d344f4016f5cd594
parentdba14814a69143a8763ed4276a38fa9509b5973d
[AArch64] Convert CMP/SELECT sign patterns to OR & ASR.

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]);
    }

Reviewed By: dmgreen

Differential Revision: https://reviews.llvm.org/D96596
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/test/CodeGen/AArch64/cmp-select-sign.ll