This is an archive of the discontinued LLVM Phabricator instance.

[ARM] add overrides for isCheapToSpeculateCttz() and isCheapToSpeculateCtlz()
ClosedPublic

Authored by spatel on Nov 6 2015, 4:33 PM.

Details

Summary

I'm a long way from home on this one...
Believe it or not, this is one step towards solving PR24818:
https://llvm.org/bugs/show_bug.cgi?id=24818

Some background here:
http://reviews.llvm.org/rL248439

The immediate problem is that ARM is using the default TLI cost settings for count-leading/trailing-zeros. I think this should be considered a cheap operation (and therefore fair game for speculation) for any implementation with V6T2 or later.

Another possibility is that we just invert the default settings for the base class hooks. Of the in-tree targets, I'm pretty sure that ARM64 and MIPS should also be making these ops cheap, but they're currently not.

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

ctlz:               
  clz  r0, r0
  bx  lr
cttz:              
  rbit  r0, r0
  clz  r0, r0
  bx  lr

Instead of:

ctlz:    
  cmp  r0, #0
  moveq  r0, #32
  clzne  r0, r0
  bx  lr
cttz:     
  cmp   r0, #0
  moveq  r0, #32
  rbitne  r0, r0
  clzne  r0, r0
  bx  lr

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 39608.Nov 6 2015, 4:33 PM
spatel retitled this revision from to [ARM] add overrides for isCheapToSpeculateCttz() and isCheapToSpeculateCtlz().
spatel updated this object.
spatel added a subscriber: llvm-commits.
rengolin accepted this revision.Nov 10 2015, 2:25 AM
rengolin edited edge metadata.

Hi Sanjay,

The logic seems sound. I'm curious as to why the lit.local.cfg wasn't there in the first place. :)

LGTM, with maybe a split, committing the lit config first, then the change itself.

cheers,
--renato

This revision is now accepted and ready to land.Nov 10 2015, 2:25 AM

The logic seems sound. I'm curious as to why the lit.local.cfg wasn't there in the first place. :)

LGTM, with maybe a split, committing the lit config first, then the change itself.

Thanks, Renato! The lit config isn't there because the directory isn't there at all. This would be the first ARM-specific regression test under SimplifyCFG.

Thanks, Renato! The lit config isn't there because the directory isn't there at all. This would be the first ARM-specific regression test under SimplifyCFG.

Ops, I missed that. :) LGTM as is. Thanks!

This revision was automatically updated to reflect the committed changes.