Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2782,8 +2782,8 @@ void SelectionDAGISel::UpdateChains(
/// induce cycles in the DAG) and if so, creating a TokenFactor node. that will
/// be used as the input node chain for the generated nodes.
static SDValue
HandleMergeInputChains(SmallVectorImpl<SDNode*> &ChainNodesMatched,
SelectionDAG *CurDAG) {
HandleMergeInputChains(SmallVectorImpl<SDNode *> &ChainNodesMatched,
SDValue InputGlue, SelectionDAG *CurDAG) {

SmallPtrSet<const SDNode *, 16> Visited;
SmallVector<const SDNode *, 8> Worklist;
Expand Down Expand Up @@ -2826,8 +2826,16 @@ HandleMergeInputChains(SmallVectorImpl<SDNode*> &ChainNodesMatched,
// node that is both the predecessor and successor of the
// to-be-merged nodes. Fail.
Visited.clear();
for (SDValue V : InputChains)
for (SDValue V : InputChains) {
// If we need to create a TokenFactor, and any of the input chains will
// also be glued to the output, we cannot merge the chains. The TokenFactor
// would prevent the glue from being honored.
if (InputChains.size() != 1 &&
V->getValueType(V->getNumValues() - 1) == MVT::Glue &&
InputGlue.getNode() == V.getNode())
return SDValue();
Worklist.push_back(V.getNode());
}

for (auto *N : ChainNodesMatched)
if (SDNode::hasPredecessorHelper(N, Visited, Worklist, Max, true))
Expand Down Expand Up @@ -3989,7 +3997,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
}

// Merge the input chains if they are not intra-pattern references.
InputChain = HandleMergeInputChains(ChainNodesMatched, CurDAG);
InputChain = HandleMergeInputChains(ChainNodesMatched, InputGlue, CurDAG);

if (!InputChain.getNode())
break; // Failed to merge.
Expand Down Expand Up @@ -4033,7 +4041,7 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
break;

// Merge the input chains if they are not intra-pattern references.
InputChain = HandleMergeInputChains(ChainNodesMatched, CurDAG);
InputChain = HandleMergeInputChains(ChainNodesMatched, InputGlue, CurDAG);

if (!InputChain.getNode())
break; // Failed to merge.
Expand Down
10 changes: 10 additions & 0 deletions llvm/test/CodeGen/X86/pr63790.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; RUN: llc < %s -mtriple=x86_64 | FileCheck %s

define void @f(ptr %0, i64 %1) {
BB:
%fps = load <2 x ptr>, ptr %0
%fp = extractelement <2 x ptr> %fps, i64 %1
%p = call ptr %fp(i32 42)
store <2 x ptr> %fps, ptr %p
ret void
}
Loading