Skip to content

Commit eea5c29

Browse files
authored
[DAGCombiner] Pass SDNodeFlags to getNode instead of modifying nodes. (#148744)
getNode has logic to intersect flags correctly if the new node happens to CSE with an existing node. Setting node flags after getNode bypasses this logic and may change the node for other uses where the flags don't hold.
1 parent 9a9db2a commit eea5c29

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13485,11 +13485,9 @@ SDValue DAGCombiner::visitSELECT_CC(SDNode *N) {
1348513485

1348613486
// Fold to a simpler select_cc
1348713487
if (SCC.getOpcode() == ISD::SETCC) {
13488-
SDValue SelectOp =
13489-
DAG.getNode(ISD::SELECT_CC, DL, N2.getValueType(), SCC.getOperand(0),
13490-
SCC.getOperand(1), N2, N3, SCC.getOperand(2));
13491-
SelectOp->setFlags(SCC->getFlags());
13492-
return SelectOp;
13488+
return DAG.getNode(ISD::SELECT_CC, DL, N2.getValueType(),
13489+
SCC.getOperand(0), SCC.getOperand(1), N2, N3,
13490+
SCC.getOperand(2), SCC->getFlags());
1349313491
}
1349413492
}
1349513493

@@ -28640,9 +28638,9 @@ SDValue DAGCombiner::foldSelectOfBinops(SDNode *N) {
2864028638
SDValue N10 = N1.getOperand(0);
2864128639
SDValue N20 = N2.getOperand(0);
2864228640
SDValue NewSel = DAG.getSelect(DL, N10.getValueType(), N0, N10, N20);
28643-
SDValue NewBinOp = DAG.getNode(BinOpc, DL, OpVTs, NewSel, N1.getOperand(1));
28644-
NewBinOp->setFlags(N1->getFlags());
28645-
NewBinOp->intersectFlagsWith(N2->getFlags());
28641+
SDNodeFlags Flags = N1->getFlags() & N2->getFlags();
28642+
SDValue NewBinOp =
28643+
DAG.getNode(BinOpc, DL, OpVTs, {NewSel, N1.getOperand(1)}, Flags);
2864628644
return SDValue(NewBinOp.getNode(), N1.getResNo());
2864728645
}
2864828646

@@ -28654,10 +28652,9 @@ SDValue DAGCombiner::foldSelectOfBinops(SDNode *N) {
2865428652
// Second op VT might be different (e.g. shift amount type)
2865528653
if (N11.getValueType() == N21.getValueType()) {
2865628654
SDValue NewSel = DAG.getSelect(DL, N11.getValueType(), N0, N11, N21);
28655+
SDNodeFlags Flags = N1->getFlags() & N2->getFlags();
2865728656
SDValue NewBinOp =
28658-
DAG.getNode(BinOpc, DL, OpVTs, N1.getOperand(0), NewSel);
28659-
NewBinOp->setFlags(N1->getFlags());
28660-
NewBinOp->intersectFlagsWith(N2->getFlags());
28657+
DAG.getNode(BinOpc, DL, OpVTs, {N1.getOperand(0), NewSel}, Flags);
2866128658
return SDValue(NewBinOp.getNode(), N1.getResNo());
2866228659
}
2866328660
}

0 commit comments

Comments
 (0)