This is an archive of the discontinued LLVM Phabricator instance.

[TTI] improved cost heuristic for cttz/ctlz calls.
ClosedPublic

Authored by andreadb on Feb 11 2015, 5:50 AM.

Details

Summary

This is a follow-up of the patch committed by James at r228826 (see D7506).

Now that SimplifyCFG uses TargetTransformInfo for cost analysis, we have to fix the cost heuristic for intrinsic calls to cttz/ctlz.

Revision r224899 (reviewed here: D6728) added two new hooks to TLI to let targets define whether cttz/ctlz are cheap or not. For example, on x86, ctlz is very expensive if the target doesn't have feature LZCNT.

This patch defines method getIntrinsicCost in BasicTTIImpl: now BasicTTIImpl queries TLI to check how expensive is a call to cttz/ctlz for the target.

I added some test cases in Transforms/SimplifyCFG/X86 to verify that SimplifyCFG only speculates cttz/ctlz when those are "cheap" for the target. I also removed a test case in SimplifyCFG/SpeculativelyExec.ll since it is not profitable to speculate a slow call to cttz even if we pass flag -phi-node-folding-threshold=2 to opt.

Please let me know if ok to submit.

P.s. The long term goal (if possible) is to migrate the logic added in CodeGenPrepare at r224899 into SimplifyCFG.

Diff Detail

Repository
rL LLVM

Event Timeline

andreadb updated this revision to Diff 19744.Feb 11 2015, 5:50 AM
andreadb retitled this revision from to [TTI] improved cost heuristic for cttz/ctlz calls..
andreadb updated this object.
andreadb edited the test plan for this revision. (Show Details)
andreadb added reviewers: hfinkel, jmolloy.
andreadb added a subscriber: Unknown Object (MLST).
hfinkel accepted this revision.Feb 11 2015, 5:58 AM
hfinkel edited edge metadata.

LGTM.

This revision is now accepted and ready to land.Feb 11 2015, 5:58 AM
This revision was automatically updated to reflect the committed changes.

Hi Hal,
Thanks for the quick review!
Committed revision 228829.