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

Fiona Glaser fglaser at apple.com
Mon Feb 9 07:05:27 PST 2015


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;
}

Fiona

-------------- next part --------------
A non-text attachment was scrubbed...
Name: floatcvtfold.diff
Type: application/octet-stream
Size: 4078 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150209/aa8914d2/attachment.obj>


More information about the llvm-commits mailing list