@@ -26897,7 +26897,8 @@ SDValue DAGCombiner::foldSelectOfBinops(SDNode *N) {
26897
26897
SDLoc DL(N);
26898
26898
26899
26899
unsigned BinOpc = N1.getOpcode();
26900
- if (!TLI.isBinOp(BinOpc) || (N2.getOpcode() != BinOpc))
26900
+ if (!TLI.isBinOp(BinOpc) || (N2.getOpcode() != BinOpc) ||
26901
+ (N1.getResNo() != N2.getResNo()))
26901
26902
return SDValue();
26902
26903
26903
26904
// The use checks are intentionally on SDNode because we may be dealing
@@ -26914,26 +26915,29 @@ SDValue DAGCombiner::foldSelectOfBinops(SDNode *N) {
26914
26915
// Fold select(cond, binop(x, y), binop(z, y))
26915
26916
// --> binop(select(cond, x, z), y)
26916
26917
if (N1.getOperand(1) == N2.getOperand(1)) {
26917
- SDValue NewSel =
26918
- DAG.getSelect(DL, VT, N0, N1.getOperand(0), N2.getOperand(0));
26918
+ SDValue N10 = N1.getOperand(0);
26919
+ SDValue N20 = N2.getOperand(0);
26920
+ SDValue NewSel = DAG.getSelect(DL, N10.getValueType(), N0, N10, N20);
26919
26921
SDValue NewBinOp = DAG.getNode(BinOpc, DL, OpVTs, NewSel, N1.getOperand(1));
26920
26922
NewBinOp->setFlags(N1->getFlags());
26921
26923
NewBinOp->intersectFlagsWith(N2->getFlags());
26922
- return NewBinOp;
26924
+ return SDValue( NewBinOp.getNode(), N1.getResNo()) ;
26923
26925
}
26924
26926
26925
26927
// Fold select(cond, binop(x, y), binop(x, z))
26926
26928
// --> binop(x, select(cond, y, z))
26927
- // Second op VT might be different (e.g. shift amount type)
26928
- if (N1.getOperand(0) == N2.getOperand(0) &&
26929
- VT == N1.getOperand(1).getValueType() &&
26930
- VT == N2.getOperand(1).getValueType()) {
26931
- SDValue NewSel =
26932
- DAG.getSelect(DL, VT, N0, N1.getOperand(1), N2.getOperand(1));
26933
- SDValue NewBinOp = DAG.getNode(BinOpc, DL, OpVTs, N1.getOperand(0), NewSel);
26934
- NewBinOp->setFlags(N1->getFlags());
26935
- NewBinOp->intersectFlagsWith(N2->getFlags());
26936
- return NewBinOp;
26929
+ if (N1.getOperand(0) == N2.getOperand(0)) {
26930
+ SDValue N11 = N1.getOperand(1);
26931
+ SDValue N21 = N2.getOperand(1);
26932
+ // Second op VT might be different (e.g. shift amount type)
26933
+ if (N11.getValueType() == N21.getValueType()) {
26934
+ SDValue NewSel = DAG.getSelect(DL, N11.getValueType(), N0, N11, N21);
26935
+ SDValue NewBinOp =
26936
+ DAG.getNode(BinOpc, DL, OpVTs, N1.getOperand(0), NewSel);
26937
+ NewBinOp->setFlags(N1->getFlags());
26938
+ NewBinOp->intersectFlagsWith(N2->getFlags());
26939
+ return SDValue(NewBinOp.getNode(), N1.getResNo());
26940
+ }
26937
26941
}
26938
26942
26939
26943
// TODO: Handle isCommutativeBinOp patterns as well?
0 commit comments