This is an archive of the discontinued LLVM Phabricator instance.

[x86] Refactor a PowerPC specific ctlz/srl transformation (NFC).
ClosedPublic

Authored by pgousseau on Aug 12 2016, 5:24 AM.

Details

Summary

Following the discussion on D22038, this refactors a PowerPC specific setcc -> srl(ctlz) transformation so it can be used by other targets.

Diff Detail

Repository
rL LLVM

Event Timeline

pgousseau updated this revision to Diff 67823.Aug 12 2016, 5:24 AM
pgousseau retitled this revision from to [x86] Refactor a PowerPC specific ctlz/srl transformation (NFC)..
pgousseau updated this object.
pgousseau added a subscriber: llvm-commits.
hfinkel added inline comments.
include/llvm/Target/TargetLowering.h
3061 ↗(On Diff #67823)

Please add a comment here explaining what this function does, including its relationship to isCtlzFast.

spatel added inline comments.Aug 12 2016, 9:33 AM
include/llvm/Target/TargetLowering.h
3061 ↗(On Diff #67823)

A better name might also help: lowerCmpEqZeroToCtlzSrl() ?

pgousseau updated this revision to Diff 67855.Aug 12 2016, 10:43 AM

Renaming method and adding comment following Hal and Sanjay comments.

spatel edited edge metadata.Aug 15 2016, 8:29 AM

Just a couple of nits, otherwise LGTM.
But please wait for Hal's feedback on the requested function comment.

lib/CodeGen/SelectionDAG/TargetLowering.cpp
3566–3567 ↗(On Diff #67855)

Indentation looks wrong - use clang-format.
Also, I know it's a giant mess, but I assume that we should use the current naming convention when creating a new function, so "Lower" -> "lower".

3572 ↗(On Diff #67855)

I think it's ok for this patch to be a cut-and-paste and NFC, but a couple of possible improvements for a follow-up:

  1. Sink 'dl' below the first two 'if' statements.
  2. Do we need to use a target-specific type rather than hard-coding MVT::i32 under this?
pgousseau added inline comments.Aug 15 2016, 10:27 AM
lib/CodeGen/SelectionDAG/TargetLowering.cpp
3572 ↗(On Diff #67855)

Sounds good, only I am not sure I understand point 2, are you suggesting to pass the value type as a parameter to this new method?

spatel added inline comments.Aug 15 2016, 10:39 AM
lib/CodeGen/SelectionDAG/TargetLowering.cpp
3572 ↗(On Diff #67855)

Sorry, I hadn't looked at D23446 when I made this comment. I see that adds a param for 'ExtTy'. I was also wondering what would happen if a target, for example, only had ctlz for a 64-bit type (or it might only have it for a smaller type than i32). I think some more customization would be needed.

But to keep it simple, we don't need to deal with any of that in this patch.

hfinkel added inline comments.Aug 15 2016, 10:59 AM
include/llvm/Target/TargetLowering.h
3063 ↗(On Diff #67855)

I think it would be clearer if you include in the comment the form of the transform; something like:

// seteq(x, 0) -> truncate(srl(ctlz(zext(x)), log2(#bits)))
pgousseau updated this revision to Diff 68052.Aug 15 2016, 11:06 AM
pgousseau edited edge metadata.

clang-format and fix method name following Sanjay's comments.

pgousseau updated this revision to Diff 68149.Aug 16 2016, 2:12 AM

Add form of the transform in the comment following Hal's comment.

hfinkel accepted this revision.Aug 16 2016, 6:04 AM
hfinkel added a reviewer: hfinkel.

Add form of the transform in the comment following Hal's comment.

LGTM, thanks.

This revision is now accepted and ready to land.Aug 16 2016, 6:04 AM
This revision was automatically updated to reflect the committed changes.