<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 Jan 27, 2015, at 12:00 AM, Owen Anderson <<a href="mailto:resistor@mac.com" class="">resistor@mac.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">On Jan 26, 2015, at 5:39 PM, Fiona Glaser <<a href="mailto:fglaser@apple.com" class="">fglaser@apple.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">The aext -> select_cc here is OK, but in your patch it will combine zext (setcc) -> setcc. On a target that uses ZeroOrNegativeOneBooleanContent, that would produce a wider type with 0 upper bits which is not the same as the all 1 bits the larger compare result would give. There are also a lot of pre-existing bugs that mishandle this now that still assume 0/1 setcc results.<br class=""><br class="">I guess I don't understand why this wouldn't already be happening during legalization if getSetCCResultType gives i32. I would not expect two different result types for the same setcc to ever work.<br class=""><br class="">-Matt<br class=""><br class=""></blockquote><br class="">What should one do if there are multiple valid SetCC result types?<br class=""><br class="">I checked the code for the out-of-tree target, and it has i16 set to the default result type, but the target also supports i32. Is the problem that LLVM doesn’t support optimizing for the case of a target that can pick and choose its SetCC result type?<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">It seems like the best solution might be to optimize the sequence to SELECT_CC instead of SETCC if the type in question is not the default SETCC type for the target.  I believe you can find *that* out by checking getSetCCResultType.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">—Owen</span></div></blockquote></div><br class=""><div class="">I just tried this and ran into some very weird results.</div><div class=""><br class=""></div><div class="">So the current code does this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">    </span>// zext(setcc x,y,cc) -> select_cc x, y, 1, 0, cc</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">    <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">SDValue</span> SCC =</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">      <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">SimplifySelectCC</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">SDLoc</span>(N), N0.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getOperand</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>), N0.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getOperand</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>),</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">                       <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">DAG</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getConstant</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>, VT), <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">DAG</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getConstant</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>, VT),</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">                       <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">cast</span><<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">CondCodeSDNode</span>>(N0.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getOperand</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span>))-><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">get</span>(), <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">true</span>);</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">    <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> (SCC.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getNode</span>()) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> SCC;</div></div><div class=""><br class=""></div><div class="">which feels a bit broken, because the function called only succeeds if it manages to *simplify* the SELECT_CC, as far as I see, and it fails in this case because there’s no simplification to be done. So I added this after:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo; color: rgb(61, 29, 129);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">    </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> (!LegalOperations || </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">TLI</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">.</span>isOperationLegal<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">ISD</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">::</span>SELECT_CC<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">, VT))</span></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">      <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">DAG</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getNode</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">ISD</span>::<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">SELECT_CC</span>, <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">SDLoc</span>(N), VT, N0.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getOperand</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>),</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">                         N0.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getOperand</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>), <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">DAG</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getConstant</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span>, VT),</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">                         <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">DAG</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getConstant</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span>, VT), N0.<span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">getOperand</span>(<span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span>));</div></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">and this actually causes the DAG to infinite-loop, because it then goes and breaks up the SELECT_CC into a SETCC + ZEXT later, presumably, then combines it again. This *also* affects the out-of-tree target, because despite the setcc/select_cc both being legal operations with VT==i32, the DAG nevertheless tries to canonicalize it into an infinite loop.</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class="">Fiona</div></body></html>