[PATCH] SelectionDAG: fold (fp_to_u/sint (u/sint_to_fp val)) when possible

Chandler Carruth chandlerc at google.com
Mon Feb 9 11:29:13 PST 2015


On Mon, Feb 9, 2015 at 7:05 AM, Fiona Glaser <fglaser at apple.com> wrote:

> This originally came up on IR for an out-of-tree target, but some test C
> code showed this is actually a general optimization we’re missing. gcc
> optimizes this one, so I figure we should probably do it too.
>
> The basic idea is that converting from Type A to float to Type B can be
> optimized out, regardless of float modes (even in safe math!) if:
>
> a) the float can precisely represent the full range of all values in Type A
> b) Type B has a strictly equal to or larger range than Type A.
>
> If Type A == Type B we can drop the operation entirely; otherwise we can
> convert it to a zero_extend or sign_extend depending on the types.
>
> A quick C example for testing that gcc gets but not clang:
>
> int32_t foo(uint8_t x) {
>     return (int32_t)(float)x;
> }
>

This seems really nice, but why do this in the SDAG? It would seem much
better to do this in instcombine.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150209/50af956b/attachment.html>


More information about the llvm-commits mailing list