<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 9, 2015 at 7:05 AM, Fiona Glaser <span dir="ltr"><<a href="mailto:fglaser@apple.com" target="_blank">fglaser@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div id=":497" class="a3s" style="overflow:hidden">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.<br>
<br>
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:<br>
<br>
a) the float can precisely represent the full range of all values in Type A<br>
b) Type B has a strictly equal to or larger range than Type A.<br>
<br>
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.<br>
<br>
A quick C example for testing that gcc gets but not clang:<br>
<br>
int32_t foo(uint8_t x) {<br>
    return (int32_t)(float)x;<br>
}<br></div></blockquote></div><br>This seems really nice, but why do this in the SDAG? It would seem much better to do this in instcombine.</div></div>