diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -8305,10 +8305,16 @@ /// else return NULL. SDNode *SelectionDAG::getNodeIfExists(unsigned Opcode, SDVTList VTList, ArrayRef Ops) { - SDNodeFlags Flags; if (Inserter) - Flags = Inserter->getFlags(); - return getNodeIfExists(Opcode, VTList, Ops, Flags); + return getNodeIfExists(Opcode, VTList, Ops, Inserter->getFlags()); + if (VTList.VTs[VTList.NumVTs - 1] != MVT::Glue) { + FoldingSetNodeID ID; + AddNodeIDNode(ID, Opcode, VTList, Ops); + void *IP = nullptr; + if (SDNode *E = FindNodeOrInsertPos(ID, SDLoc(), IP)) + return E; + } + return nullptr; } SDNode *SelectionDAG::getNodeIfExists(unsigned Opcode, SDVTList VTList, diff --git a/llvm/test/CodeGen/PowerPC/setcc-sub-flag.ll b/llvm/test/CodeGen/PowerPC/setcc-sub-flag.ll --- a/llvm/test/CodeGen/PowerPC/setcc-sub-flag.ll +++ b/llvm/test/CodeGen/PowerPC/setcc-sub-flag.ll @@ -10,7 +10,7 @@ ; CHECK: liveins: $x3, $x4 ; CHECK: [[COPY:%[0-9]+]]:g8rc = COPY $x4 ; CHECK: [[COPY1:%[0-9]+]]:g8rc = COPY $x3 - ; CHECK: [[SUBF8_:%[0-9]+]]:g8rc = SUBF8 [[COPY1]], [[COPY]] + ; CHECK: [[SUBF8_:%[0-9]+]]:g8rc = nsw SUBF8 [[COPY1]], [[COPY]] %c = sub nsw i64 %b, %a call void @foo(i64 %c) %d = icmp slt i64 %a, %b