<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><DIV><BLOCKQUOTE type="cite"><BLOCKQUOTE type="cite"></BLOCKQUOTE><BLOCKQUOTE type="cite"></BLOCKQUOTE><BLOCKQUOTE type="cite"></BLOCKQUOTE><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">It would be better to split up the "EqualTo" predicate here so that</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">there was one for FP and one for integers.<SPAN class="Apple-converted-space">  </SPAN>When the FP part of this</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">lands, you'll want "Unordered" "Equal" and "LessThan" instead of just</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">LessThan + Equal.<SPAN class="Apple-converted-space"> </SPAN></DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Okay, good idea. Could you please review the CF.patch file which is</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">attached. I think this is what you had in mind.</DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>It looks great.  However, if possible, it sure would be nice to just nuke the templates :).</DIV><BR><BLOCKQUOTE type="cite"> <BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Further, 'lessthan' drops the sign, so the code is apparently wrong.</DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I'm not following this. I thought you weren't allowed to do relational</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">operators on packed type? Are you talking about the ConstantInt case?</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">This:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">  </SPAN>static Constant *LessThan(const ConstantInt *V1, const ConstantInt</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">*V2) {</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">    </SPAN>bool R = (BuiltinType)V1->getZExtValue() <</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">(BuiltinType)V2->getZExtValue();</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">    </SPAN>return ConstantBool::get(R);</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">  </SPAN>}</DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Right, but that LessThan predicate (which always evaluates the predicate as unsigned) is also called for slt.  This is a bug.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><BR><BLOCKQUOTE type="cite"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+Constant *llvm::ConstantFoldCompareInstruction(</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">    </SPAN>unsigned opcode, Constant *C1, Constant *C2, unsigned short</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">predicate) {</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">...</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">  </SPAN>case ICmpInst::ICMP_ULT:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">  </SPAN>case ICmpInst::ICMP_SLT: <SPAN class="Apple-converted-space">  </SPAN>C = ConstRules::get(C1, C2).lessthan(C1,</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">C2);break;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">  </SPAN>case ICmpInst::ICMP_UGT:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">  </SPAN>case ICmpInst::ICMP_SGT: <SPAN class="Apple-converted-space">  </SPAN>C = ConstRules::get(C1, C2).lessthan(C2,</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">C1);break;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">  </SPAN>case ICmpInst::ICMP_ULE:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">  </SPAN>case ICmpInst::ICMP_SLE: <SPAN class="Apple-converted-space">  </SPAN>// C1 <= C2<SPAN class="Apple-converted-space">  </SPAN>===<SPAN class="Apple-converted-space">  </SPAN>!(C2 < C1)</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">    </SPAN>C = ConstRules::get(C1, C2).lessthan(C2, C1);</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">    </SPAN>if (C) return ConstantExpr::getNot(C);</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">    </SPAN>break;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">  </SPAN>case ICmpInst::ICMP_UGE:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">  </SPAN>case ICmpInst::ICMP_SGE: <SPAN class="Apple-converted-space">  </SPAN>// C1 >= C2<SPAN class="Apple-converted-space">  </SPAN>===<SPAN class="Apple-converted-space">  </SPAN>!(C1 < C2)</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">    </SPAN>C = ConstRules::get(C1, C2).lessthan(C1, C2);</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">    </SPAN>if (C) return ConstantExpr::getNot(C);</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">+<SPAN class="Apple-converted-space">    </SPAN>break;</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">These drop the sign of the comparison, which is a serious bug.<SPAN class="Apple-converted-space">  </SPAN>I'd</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">expect this to miscompile things like:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space"> </SPAN>%X = iset slt ubyte 0, ubyte 128</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">... or whatever the syntax is.</DIV> </BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">The LessThan code above for ConstantInt works fine. It extracts the</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">canonical ZExt form then casts each operand to the correct type before</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">doing the compare:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><SPAN class="Apple-converted-space">   </SPAN>bool R = (BuiltinType)V1->getZExtValue() <</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">(BuiltinType)V2->getZExtValue();</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I don't see the problem.<SPAN class="Apple-converted-space"> </SPAN></DIV></BLOCKQUOTE><DIV><BR class="khtml-block-placeholder"></DIV><DIV>The code is trying to do a signed less than comparison, you're always doing an unsigned comparison.</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I will look into '<B>SETCC InstructionCombining.cpp' next, but not tonight.</B></DIV><DIV><B><BR class="khtml-block-placeholder"></B></DIV><DIV><B>-Chris</B></DIV><BR></DIV><BR></BODY></HTML>