<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><DIV><SPAN class="Apple-style-span">This patch fixes several routines which deal with negation but failed to use the proper floating point negation formula, <I>f(x) = -0.0 - x</I>, for vectors. I simply factored out the logic to get the properly-signed "zero" value and extended it to get the correct floating-point vector.</SPAN></DIV><DIV><BR></DIV><DIV>In most cases, these local logic errors were harmless because callers operated exclusively on scalar integers, but in four cases there look to be potential problems or missed optimizations.</DIV><DIV><BR></DIV><DIV><SPAN class="Apple-style-span">This patch fixes the dead <FONT class="Apple-style-span" face="Andale Mono">m_Neg</FONT> matcher that patch 3 commented out.</SPAN></DIV><DIV><BR></DIV><DIV><BR></DIV><DIV><B>at lib/Transforms/Scalar/InstructionCombining.cpp:6788:</B></DIV><DIV><BR></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">  NegVal = InsertNewInstBefore(</FONT></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">    BinaryOperator::createNeg(SubOp->getOperand(1), "tmp"), SI);</FONT></DIV><DIV><BR></DIV><DIV><SPAN class="Apple-style-span">This can pass vectors to <FONT class="Apple-style-span" face="Andale Mono">createNeg</FONT> and looks like it would previous miscompile code by inserting a <FONT class="Apple-style-span" face="Andale Mono">sub <+0.0, +0.0, etc.>, %x</FONT> as it simplifies an expression. This patch should fix this case.</SPAN></DIV><DIV><BR></DIV><DIV><BR></DIV><DIV><B>at lib/Target/CBackend/CBackend.cpp:2129</B></DIV><DIV><BR></DIV><DIV>This is now <A href="http://llvm.org/PR1126">http://llvm.org/PR1126</A>.</DIV><DIV><BR></DIV><DIV><BR></DIV><DIV><B>at lib/Transforms/Scalar/InstructionCombining.cpp:325:</B></DIV><DIV><BR></DIV><DIV><SPAN class="Apple-style-span">Please review this call site in getComplexity. It is clearly reachable with FP vector operands, and <FONT class="Apple-style-span" face="Andale Mono">isNeg</FONT> will now return true for vector negation, which is not a single machine instruction as fneg or integer negation are. Therefore, existing behavior might be preferable? If so, exclude vectors:</SPAN></DIV><DIV>    <BR class="khtml-block-placeholder"></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">      - if (BinaryOperator::isNeg(V) || BinaryOperator::isNot(V))</FONT></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">      + if ((!isa<PackedType>(V->getType()) && BinaryOperator::isNeg(V)) ||</FONT></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">      +     BinaryOperator::isNot(V))</FONT></DIV><DIV><BR></DIV><DIV><BR></DIV><DIV><B>at lib/Transforms/Scalar/InstructionCombining.cpp:473:</B></DIV><DIV><BR></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">static inline Value *dyn_castNegVal(Value *V) {</FONT></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">  if (BinaryOperator::isNeg(V))</FONT></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">    return BinaryOperator::getNegArgument(V);</FONT></DIV><DIV><BR></DIV><DIV>This could clearly be invoked with FP vector operands. With this patch, the following transformations would be extended to FP vectors:</DIV><DIV><BR></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">    -A + B   -->  B - A</FONT></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">    A + -B   -->  A - B</FONT></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">    A - (-B) -->  A + B</FONT></DIV><DIV><FONT class="Apple-style-span" face="Andale Mono">    -X * -Y  -->  X * Y</FONT></DIV><DIV><BR></DIV><DIV>These would already have applied to scalar FP operations, so I have to assume that they're IEEE-approved.</DIV><DIV><BR></DIV><DIV><BR></DIV><DIV>Just one more!</DIV><DIV><DIV><BR class="khtml-block-placeholder"></DIV>— Gordon<BR class="Apple-interchange-newline"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV></BODY></HTML>