<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Nicolas,<div><br></div><div><div><div><div>On 1-Apr-09, at 7:34 AM, Nicolas Capens wrote:</div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div lang="EN-US" link="blue" vlink="purple"><div class="Section1"><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; ">I’m having some trouble understanding the following lines in InstructionCombining.cpp, which possibly contain a bug:</div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p></o:p></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 10pt; font-family: 'Courier New'; color: blue; ">if</span><span style="font-size: 10pt; font-family: 'Courier New'; "><span class="Apple-converted-space"> </span>(Mask[i] >= 2*e)<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 10pt; font-family: 'Courier New'; ">    NewMask.push_back(2*e);<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 10pt; font-family: 'Courier New'; color: blue; ">else<o:p></o:p></span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; "><span style="font-size: 10pt; font-family: 'Courier New'; ">    NewMask.push_back(LHSMask[Mask[i]]);</span><o:p></o:p></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; "><o:p> </o:p></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 11pt; font-family: Calibri, sans-serif; ">When Mask[i] is bigger than the size of LHSMask it reads out of bounds on that last line. I believe the first line is there to try to prevent that but then it should be comparing to LHSMask.size() not 2*e (e being Mask.size()). </div></div></div></span></blockquote><div><br></div><div>Upon quick inspection of the code, I don't think this is necessarily a bug right now, but the function could be improved.</div><div><br></div>I believe this stems (in part at least) from the fact that shufflevector used to require that the sources and the mask have the same size, which was changed a few months ago to allow an arbitrarily-sized mask.</div><div><br></div><div>This would be a bug all throughout this function (which generally assumes this is still the case), if the function didn't do the following check early:</div><div><br></div><div><div>  unsigned VWidth = cast<VectorType>(SVI.getType())->getNumElements();</div><div><br></div><div>  if (VWidth != cast<VectorType>(LHS->getType())->getNumElements())</div><div>    return 0;</div><div><br></div><div>In other words, if the mask size is not equal to the number of elements in the vectors, it skips this transformation.</div><div><br></div><div>Because the LHS is a shufflevector in the part of the code you are mentioning, and the result of a shufflevector has the same number of elements as its mask, you are actually guaranteed that LHSMask.size() == Mask.size(), because LHSMask.size() == LHS->getNumElements() == Mask.size().</div><div><br></div><div>It shouldn't be too hard to relax the constraint that this optimization requires the number of elements being shuffle to be equal to the mask size, but it'll probably take some careful testing!</div><div><br></div><div>Stefanus</div><div><br></div></div><div apple-content-edited="true"> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>--</div><div>Stefanus Du Toit <<a href="mailto:stefanus.dutoit@rapidmind.com">stefanus.dutoit@rapidmind.com</a>></div><div>  RapidMind Inc.</div><div>  phone: +1 519 885 5455 x116 -- fax: +1 519 885 1463</div><div><br class="khtml-block-placeholder"></div></div></div></div></div></span><br class="Apple-interchange-newline"> </div><br></div></div></body></html>