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