@@ -7171,7 +7171,11 @@ SDValue DAGCombiner::visitSIGN_EXTEND(SDNode *N) {
7171
7171
SDValue Trunc = DAG.getNode(ISD::TRUNCATE, SDLoc(N0),
7172
7172
N0.getValueType(), ExtLoad);
7173
7173
ExtendSetCCUses(SetCCs, Trunc, ExtLoad, DL, ISD::SIGN_EXTEND);
7174
- CombineTo(N0.getNode(), Trunc, ExtLoad.getValue(1));
7174
+ // If the load value is used only by N, replace it via CombineTo N.
7175
+ if (N0.getValue(0).hasOneUse())
7176
+ DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
7177
+ else
7178
+ CombineTo(LN0, Trunc, ExtLoad.getValue(1));
7175
7179
return CombineTo(N, ExtLoad); // Return N so it doesn't get rechecked!
7176
7180
}
7177
7181
}
@@ -7229,7 +7233,11 @@ SDValue DAGCombiner::visitSIGN_EXTEND(SDNode *N) {
7229
7233
SDLoc(N0.getOperand(0)),
7230
7234
N0.getOperand(0).getValueType(), ExtLoad);
7231
7235
ExtendSetCCUses(SetCCs, Trunc, ExtLoad, DL, ISD::SIGN_EXTEND);
7232
- CombineTo(N0.getOperand(0).getNode(), Trunc, ExtLoad.getValue(1));
7236
+ // If the load value is used only by N, replace it via CombineTo N.
7237
+ if (SDValue(LN0, 0).hasOneUse())
7238
+ DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
7239
+ else
7240
+ CombineTo(LN0, Trunc, ExtLoad.getValue(1));
7233
7241
return CombineTo(N, And); // Return N so it doesn't get rechecked!
7234
7242
}
7235
7243
}
@@ -7470,7 +7478,11 @@ SDValue DAGCombiner::visitZERO_EXTEND(SDNode *N) {
7470
7478
SDValue Trunc = DAG.getNode(ISD::TRUNCATE, SDLoc(N0),
7471
7479
N0.getValueType(), ExtLoad);
7472
7480
ExtendSetCCUses(SetCCs, Trunc, ExtLoad, SDLoc(N), ISD::ZERO_EXTEND);
7473
- CombineTo(N0.getNode(), Trunc, ExtLoad.getValue(1));
7481
+ // If the load value is used only by N, replace it via CombineTo N.
7482
+ if (SDValue(LN0, 0).hasOneUse())
7483
+ DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
7484
+ else
7485
+ CombineTo(LN0, Trunc, ExtLoad.getValue(1));
7474
7486
return CombineTo(N, ExtLoad); // Return N so it doesn't get rechecked!
7475
7487
}
7476
7488
}
@@ -7522,7 +7534,11 @@ SDValue DAGCombiner::visitZERO_EXTEND(SDNode *N) {
7522
7534
SDLoc(N0.getOperand(0)),
7523
7535
N0.getOperand(0).getValueType(), ExtLoad);
7524
7536
ExtendSetCCUses(SetCCs, Trunc, ExtLoad, DL, ISD::ZERO_EXTEND);
7525
- CombineTo(N0.getOperand(0).getNode(), Trunc, ExtLoad.getValue(1));
7537
+ // If the load value is used only by N, replace it via CombineTo N.
7538
+ if (SDValue(LN0, 0).hasOneUse())
7539
+ DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
7540
+ else
7541
+ CombineTo(LN0, Trunc, ExtLoad.getValue(1));
7526
7542
return CombineTo(N, And); // Return N so it doesn't get rechecked!
7527
7543
}
7528
7544
}
@@ -7695,13 +7711,16 @@ SDValue DAGCombiner::visitANY_EXTEND(SDNode *N) {
7695
7711
LN0->getChain(),
7696
7712
LN0->getBasePtr(), N0.getValueType(),
7697
7713
LN0->getMemOperand());
7698
- CombineTo(N, ExtLoad);
7699
7714
SDValue Trunc = DAG.getNode(ISD::TRUNCATE, SDLoc(N0),
7700
7715
N0.getValueType(), ExtLoad);
7701
- CombineTo(N0.getNode(), Trunc, ExtLoad.getValue(1));
7702
7716
ExtendSetCCUses(SetCCs, Trunc, ExtLoad, SDLoc(N),
7703
7717
ISD::ANY_EXTEND);
7704
- return SDValue(N, 0); // Return N so it doesn't get rechecked!
7718
+ // If the load value is used only by N, replace it via CombineTo N.
7719
+ if (N0.hasOneUse())
7720
+ DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
7721
+ else
7722
+ CombineTo(LN0, Trunc, ExtLoad.getValue(1));
7723
+ return CombineTo(N, ExtLoad); // Return N so it doesn't get rechecked!
7705
7724
}
7706
7725
}
7707
7726
0 commit comments