This is an archive of the discontinued LLVM Phabricator instance.

[TTI] Teach the cost heuristic how to query TLI to check if a zext/trunc is "free" for the target.
ClosedPublic

Authored by andreadb on Feb 12 2015, 5:26 AM.

Details

Summary

Now that SimplifyCFG uses TTI for the cost heuristic, we can teach BasicTTIImpl how to query TLI in order to get a more accurate cost for truncates and zero-extends.

Before this patch, the basic cost heuristic (see TargetTransformInfoImplCRTPBase) would have conservatively returned a 'default' TCC_Basic for all zero-extends, and TCC_Free for truncates on native types.

This patch improves that logic so that we query TLI if available to get more accurate answers. If TLI is available, then we know we can call methods 'isZExtFree' and 'isTruncateFree' to check if a zext/trunc is free for the target.

Added more test cases in SimplifyCFG/X86/speculate-cttz-ctlz.ll. With this change, SimplifuCFG is now able to speculate a "cheap" cttz/ctlz immediately followed by a free zext/trunc.

This patch would make redundant the logic originally added in CodeGenPrepare at r225274 (reviewed here: D6853).
I plan to send other patches to remove that logic from CodeGenPrepare.

Please let me know if ok to submit.
Thanks,
Andrea

Diff Detail

Repository
rL LLVM

Event Timeline

andreadb updated this revision to Diff 19819.Feb 12 2015, 5:26 AM
andreadb retitled this revision from to [TTI] Teach the cost heuristic how to query TLI to check if a zext/trunc is "free" for the target..
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 12 2015, 5:38 AM
hfinkel edited edge metadata.

LGTM.

include/llvm/Analysis/TargetTransformInfoImpl.h
424 ↗(On Diff #19819)

Remove the comment; we're not delegating to the "fully generic" version any more.

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

Thanks Hal,

I removed the invalid comment from 'TargetTransformInfoImpl.h' and committed the patch at revision 228923.

-Andrea