<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 9, 2015 at 2:44 PM, Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><blockquote type="cite"><div>On Feb 9, 2015, at 2:26 PM, Quentin Colombet <<a href="mailto:qcolombet@apple.com" target="_blank">qcolombet@apple.com</a>> wrote:</div><br><div><div style="word-wrap:break-word"><div><br></div><div>For the instcombine part:</div><div><br></div><div>+ if (FITy->getScalarSizeInBits() > SrcTy->getScalarSizeInBits())</div><div>Shouldn’t we have some checks on the DstTy as well?</div><div><br></div><div>e.g., what happens with:</div><div>sitofp i32 to float</div><div>fptoui float to i8</div></div></div></blockquote><blockquote type="cite"><div><div style="word-wrap:break-word"><div><br></div><div>We shouldn’t be able to simplify that with a s/zext, do we… Or maybe we can because it is undef??</div></div></div></blockquote><div><br></div></span><div><div>First not all i32 can fit in a float, it is checked in the outer enclosing test.</div><div>Let’s consider instead:</div><div><br></div><div><div><div style="word-wrap:break-word"><div>sitofp i16 to float<br>fptoui float to i8<br><br></div></div></div></div><div>The result is defined only for input value that will fit in the i8 (Language Ref: " If the value cannot fit in ty2, the results are undefined.).</div><div>If that mean that we are allowed to do the transform, then we have to generate a trunc right?</div><div><br></div><div>It means also that we don’t really care checking that the input integer size can be represented in the floating point type since the same language reference quote applies, i.e. :</div><div><br></div><div>sitofp i128 to float<br>fptoso float to i128<br></div><div><br></div><div>can be turned into a no-op.</div><div><br></div><div>Chandler or someone else familiar with the details of InstCombine might be able to shed some light on what is / isn’t allowed to do when the language ref. talk about “undefined” results. </div></div></blockquote></div><br>I think "undef" is the right thing to use when you have proven that the operation has an undefined result.</div><div class="gmail_extra"><br></div><div class="gmail_extra">If you're just using 'trunc' and not caring about the values discarded because they would have resulted in undef, that also seems fine.</div></div>