[AArch64] add overrides for isCheapToSpeculateCttz() and isCheapToSpeculateCtlz()
authorSanjay Patel <spatel@rotateright.com>
Tue, 10 Nov 2015 18:11:37 +0000 (18:11 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 10 Nov 2015 18:11:37 +0000 (18:11 +0000)
commitccb762ceea71b86cdf40af65d26ce86515037e58
tree7d3122e8909fc31398fac6147c1274a27ef1673d
parent828893fcf069fafdbbfbd5878d6f2a52ed3c498b
[AArch64] add overrides for isCheapToSpeculateCttz() and isCheapToSpeculateCtlz()

AArch64 has instructions for efficient count-leading/trailing-zeros, so this should be
considered a cheap operation (and therefore fair game for speculation) for any AArch64
implementation.

The net result of allowing this speculation for the regression tests in this
patch is that we get this code:

ctlz:
  clz  w0, w0
  ret

cttz:
  rbit  w8, w0
  clz  w0, w8
  ret

Instead of:

ctlz:
  cbz  w0, .LBB0_2
  clz  w0, w0
  ret
.LBB0_2:
  orr  w0, wzr, #0x20
  ret

cttz:
  cbz  w0, .LBB1_2
  rbit  w8, w0
  clz  w0, w8
  ret
.LBB1_2:
  orr  w0, wzr, #0x20
  ret

See D14469 for the larger motivation.

Differential Revision: http://reviews.llvm.org/D14505

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252625 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/AArch64/AArch64ISelLowering.h
test/Transforms/SimplifyCFG/AArch64/cttz-ctlz.ll [new file with mode: 0644]