[MIPS] add overrides for isCheapToSpeculateCttz() and isCheapToSpeculateCtlz()
authorSanjay Patel <spatel@rotateright.com>
Wed, 11 Nov 2015 17:24:56 +0000 (17:24 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 11 Nov 2015 17:24:56 +0000 (17:24 +0000)
commit03849aaa4e9c3859d39aa2e2573a0f69d6b3eb7f
tree87ce9b17514f463506251a78768fe0f0906a5f7e
parente5bd698a3ca285e32da01c9a5c44d885cce0e29d
[MIPS] add overrides for isCheapToSpeculateCttz() and isCheapToSpeculateCtlz()

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

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

ctlz:
  jr  $ra
  clz  $2, $4

cttz:
  addiu  $1, $4, -1
  not  $2, $4
  and  $1, $2, $1
  clz  $1, $1
  addiu  $2, $zero, 32
  jr  $ra
  subu  $2, $2, $1

Instead of:

ctlz:
  beqz  $4, $BB0_2
  addiu  $2, $zero, 32
  clz  $2, $4
$BB0_2:
  jr  $ra
  nop

cttz:
  beqz  $4, $BB1_2
  addiu  $2, $zero, 32
  addiu  $1, $4, -1
  not  $2, $4
  and  $1, $2, $1
  clz  $1, $1
  addiu  $2, $zero, 32
  subu  $2, $2, $1
$BB1_2:
  jr  $ra
  nop

See D14469 for the larger motivation.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@252755 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/Mips/MipsISelLowering.cpp
lib/Target/Mips/MipsISelLowering.h
test/Transforms/SimplifyCFG/Mips/cttz-ctlz.ll [new file with mode: 0644]
test/Transforms/SimplifyCFG/Mips/lit.local.cfg [new file with mode: 0644]