[LLVMdev] Bug in SUB expansion going back to LLVM 2.6

Villmow, Micah Micah.Villmow at amd.com
Mon May 21 11:21:53 PDT 2012


I found a bug in the expansion code for SUB going back to at least LLVM 2.6 and still shows up in trunk.
case ISD::SUB: {
    EVT VT = Node->getValueType(0);
    assert(TLI.isOperationLegalOrCustom(ISD::ADD, VT) &&
           TLI.isOperationLegalOrCustom(ISD::XOR, VT) &&
           "Don't know how to expand this subtraction!");
    Tmp1 = DAG.getNode(ISD::XOR, dl, VT, Node->getOperand(1),
               DAG.getConstant(APInt::getAllOnesValue(VT.getSizeInBits()), VT));
    Tmp1 = DAG.getNode(ISD::ADD, dl, VT, Tmp2, DAG.getConstant(1, VT));
    Results.push_back(DAG.getNode(ISD::ADD, dl, VT, Node->getOperand(0), Tmp1));
    break;
  }


The problem is Tmp2 is not initialized and should be Tmp1 instead. This code only is hit if the architecture does not support 'SUB' and you need to expand it.

Patch is attached, please commit if good.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120521/c84baa82/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: isd_sub_expand.diff
Type: application/octet-stream
Size: 672 bytes
Desc: isd_sub_expand.diff
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120521/c84baa82/attachment.obj>


More information about the llvm-dev mailing list