@@ -3981,8 +3981,7 @@ SDValue DAGCombiner::visitMUL(SDNode *N) {
3981
3981
3982
3982
// fold (mul x, -1) -> 0-x
3983
3983
if (N1IsConst && ConstValue1.isAllOnes())
3984
- return DAG.getNode(ISD::SUB, DL, VT,
3985
- DAG.getConstant(0, DL, VT), N0);
3984
+ return DAG.getNegative(N0, DL, VT);
3986
3985
3987
3986
// fold (mul x, (1 << c)) -> x << c
3988
3987
if (isConstantOrConstantVector(N1, /*NoOpaques*/ true) &&
@@ -4049,7 +4048,7 @@ SDValue DAGCombiner::visitMUL(SDNode *N) {
4049
4048
DAG.getConstant(TZeros, DL, VT)))
4050
4049
: DAG.getNode(MathOp, DL, VT, Shl, N0);
4051
4050
if (ConstValue1.isNegative())
4052
- R = DAG.getNode(ISD::SUB , DL, VT, DAG.getConstant(0, DL, VT), R );
4051
+ R = DAG.getNegative(R , DL, VT);
4053
4052
return R;
4054
4053
}
4055
4054
}
@@ -4303,7 +4302,7 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
4303
4302
// fold (sdiv X, -1) -> 0-X
4304
4303
ConstantSDNode *N1C = isConstOrConstSplat(N1);
4305
4304
if (N1C && N1C->isAllOnes())
4306
- return DAG.getNode(ISD::SUB , DL, VT, DAG.getConstant(0, DL, VT), N0 );
4305
+ return DAG.getNegative(N0 , DL, VT);
4307
4306
4308
4307
// fold (sdiv X, MIN_SIGNED) -> select(X == MIN_SIGNED, 1, 0)
4309
4308
if (N1C && N1C->getAPIntValue().isMinSignedValue())
@@ -8682,8 +8681,7 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
8682
8681
// fold (not (add X, -1)) -> (neg X)
8683
8682
if (isAllOnesConstant(N1) && N0.getOpcode() == ISD::ADD &&
8684
8683
isAllOnesOrAllOnesSplat(N0.getOperand(1))) {
8685
- return DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT),
8686
- N0.getOperand(0));
8684
+ return DAG.getNegative(N0.getOperand(0), DL, VT);
8687
8685
}
8688
8686
8689
8687
// fold (xor (and x, y), y) -> (and (not x), y)
@@ -11305,8 +11303,7 @@ SDValue DAGCombiner::visitVSELECT(SDNode *N) {
11305
11303
if (SatCC == ISD::SETUGT && Other.getOpcode() == ISD::ADD &&
11306
11304
ISD::matchBinaryPredicate(OpRHS, CondRHS, MatchUSUBSAT,
11307
11305
/*AllowUndefs*/ true)) {
11308
- OpRHS = DAG.getNode(ISD::SUB, DL, VT,
11309
- DAG.getConstant(0, DL, VT), OpRHS);
11306
+ OpRHS = DAG.getNegative(OpRHS, DL, VT);
11310
11307
return DAG.getNode(ISD::USUBSAT, DL, VT, OpLHS, OpRHS);
11311
11308
}
11312
11309
@@ -12394,7 +12391,7 @@ SDValue DAGCombiner::visitSIGN_EXTEND(SDNode *N) {
12394
12391
N0.getOperand(1).getOpcode() == ISD::ZERO_EXTEND &&
12395
12392
TLI.isOperationLegalOrCustom(ISD::SUB, VT)) {
12396
12393
SDValue Zext = DAG.getZExtOrTrunc(N0.getOperand(1).getOperand(0), DL, VT);
12397
- return DAG.getNode(ISD::SUB , DL, VT, DAG.getConstant(0, DL, VT), Zext );
12394
+ return DAG.getNegative(Zext , DL, VT);
12398
12395
}
12399
12396
// Eliminate this sign extend by doing a decrement in the destination type:
12400
12397
// sext i32 ((zext i8 X to i32) + (-1)) to i64 --> (zext i8 X to i64) + (-1)
0 commit comments