<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 9, 2015, at 11:48 AM, Fiona Glaser <<a href="mailto:fglaser@apple.com" class="">fglaser@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 9, 2015, at 11:31 AM, Chandler Carruth <<a href="mailto:chandlerc@google.com" class="">chandlerc@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Feb 9, 2015 at 11:30 AM, Fiona Glaser <span dir="ltr" class=""><<a href="mailto:fglaser@apple.com" target="_blank" class="">fglaser@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I get the message ;-) Already redoing it in instcombine; turns out there’s actually already code for it, but it only triggers when TypeA == TypeB. Will have a patch in a few moments.</blockquote></div><br class="">Oh, sorry, I just totally missed Duncan's email. Sorry for the noise!</div></div>
</div></blockquote></div><br class=""><div class="">No problem, thanks for the suggestion. I will eventually figure out the intuition for whether a fold belongs in Instcombine or DAG!</div><div class=""><br class=""></div><div class="">Here’s a new patch that works in instcombine instead.</div></div></div></blockquote><div><br class=""></div><div><br class=""></div></div><div class=""><br class=""></div><div class=""><div class="">+      /* extra bit for sign */</div><div class="">+      (int)SrcTy->getScalarSizeInBits() < OpITy->getFPMantissaWidth()) {</div></div><div class=""><br class=""></div>It is present in the existing code, but I’m not sure I understand.<div class="">First, I don’t understand the strict < instead of <=.</div><div class="">Then I understand that SIToFPInst has one less bit to be considered because the sign bit cannot contribute to a value here (the comment explains why), and it wouldn’t be part of the mantissa anyway.</div><div class="">I would have written something like:</div><div class=""><br class=""></div><div class="">   bool isSigned = isa<SIToFPInst>(OpI);</div><div class=""><div class="">   if ((isa<UIToFPInst>(OpI) || isSigned) &&</div></div><div class=""><div class="">       (int)FI.getType()->getScalarSizeInBits() -  isSigned <= /*extra bit for sign */</div><div class="">                    OpI->getType()->getFPMantissaWidth())</div></div><div class=""><br class=""></div><div class=""> It would be nice to also have the test that cover this edge case.</div><div class=""><br class=""></div><div class=""><div class="">+    else if (FITy->getScalarSizeInBits() > SrcTy->getScalarSizeInBits())</div><div class="">+      return new ZExtInst(OpI->getOperand(0), FITy);</div></div><div class=""><br class=""></div><div class="">No need for ReplaceInstUsesWith() in the return statement?</div><div class=""><br class=""></div><div class="">Mehdi</div><div class=""><br class=""></div></body></html>