@@ -475,6 +475,9 @@ AArch64TargetLowering::AArch64TargetLowering(const TargetMachine &TM,
475
475
setOperationAction(ISD::CTPOP, MVT::i64, Custom);
476
476
setOperationAction(ISD::CTPOP, MVT::i128, Custom);
477
477
478
+ setOperationAction(ISD::ABS, MVT::i32, Custom);
479
+ setOperationAction(ISD::ABS, MVT::i64, Custom);
480
+
478
481
setOperationAction(ISD::SDIVREM, MVT::i32, Expand);
479
482
setOperationAction(ISD::SDIVREM, MVT::i64, Expand);
480
483
for (MVT VT : MVT::fixedlen_vector_valuetypes()) {
@@ -3968,6 +3971,22 @@ SDValue AArch64TargetLowering::LowerSTORE(SDValue Op,
3968
3971
return SDValue();
3969
3972
}
3970
3973
3974
+ // Generate SUBS and CSEL for integer abs.
3975
+ static SDValue LowerABS(SDValue Op, SelectionDAG &DAG) {
3976
+ MVT VT = Op.getSimpleValueType();
3977
+
3978
+ SDLoc DL(Op);
3979
+ SDValue Neg = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT),
3980
+ Op.getOperand(0));
3981
+ // Generate SUBS & CSEL.
3982
+ SDValue Cmp =
3983
+ DAG.getNode(AArch64ISD::SUBS, DL, DAG.getVTList(VT, MVT::i32),
3984
+ Op.getOperand(0), DAG.getConstant(0, DL, VT));
3985
+ return DAG.getNode(AArch64ISD::CSEL, DL, VT, Op.getOperand(0), Neg,
3986
+ DAG.getConstant(AArch64CC::PL, DL, MVT::i32),
3987
+ Cmp.getValue(1));
3988
+ }
3989
+
3971
3990
SDValue AArch64TargetLowering::LowerOperation(SDValue Op,
3972
3991
SelectionDAG &DAG) const {
3973
3992
LLVM_DEBUG(dbgs() << "Custom lowering: ");
@@ -4197,6 +4216,8 @@ SDValue AArch64TargetLowering::LowerOperation(SDValue Op,
4197
4216
return LowerToPredicatedOp(Op, DAG, AArch64ISD::FMINNM_PRED);
4198
4217
case ISD::VSELECT:
4199
4218
return LowerFixedLengthVectorSelectToSVE(Op, DAG);
4219
+ case ISD::ABS:
4220
+ return LowerABS(Op, DAG);
4200
4221
}
4201
4222
}
4202
4223
@@ -11323,34 +11344,6 @@ static SDValue foldVectorXorShiftIntoCmp(SDNode *N, SelectionDAG &DAG,
11323
11344
return DAG.getNode(AArch64ISD::CMGEz, SDLoc(N), VT, Shift.getOperand(0));
11324
11345
}
11325
11346
11326
- // Generate SUBS and CSEL for integer abs.
11327
- static SDValue performIntegerAbsCombine(SDNode *N, SelectionDAG &DAG) {
11328
- EVT VT = N->getValueType(0);
11329
-
11330
- SDValue N0 = N->getOperand(0);
11331
- SDValue N1 = N->getOperand(1);
11332
- SDLoc DL(N);
11333
-
11334
- // Check pattern of XOR(ADD(X,Y), Y) where Y is SRA(X, size(X)-1)
11335
- // and change it to SUB and CSEL.
11336
- if (VT.isInteger() && N->getOpcode() == ISD::XOR &&
11337
- N0.getOpcode() == ISD::ADD && N0.getOperand(1) == N1 &&
11338
- N1.getOpcode() == ISD::SRA && N1.getOperand(0) == N0.getOperand(0))
11339
- if (ConstantSDNode *Y1C = dyn_cast<ConstantSDNode>(N1.getOperand(1)))
11340
- if (Y1C->getAPIntValue() == VT.getSizeInBits() - 1) {
11341
- SDValue Neg = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT),
11342
- N0.getOperand(0));
11343
- // Generate SUBS & CSEL.
11344
- SDValue Cmp =
11345
- DAG.getNode(AArch64ISD::SUBS, DL, DAG.getVTList(VT, MVT::i32),
11346
- N0.getOperand(0), DAG.getConstant(0, DL, VT));
11347
- return DAG.getNode(AArch64ISD::CSEL, DL, VT, N0.getOperand(0), Neg,
11348
- DAG.getConstant(AArch64CC::PL, DL, MVT::i32),
11349
- SDValue(Cmp.getNode(), 1));
11350
- }
11351
- return SDValue();
11352
- }
11353
-
11354
11347
// VECREDUCE_ADD( EXTEND(v16i8_type) ) to
11355
11348
// VECREDUCE_ADD( DOTv16i8(v16i8_type) )
11356
11349
static SDValue performVecReduceAddCombine(SDNode *N, SelectionDAG &DAG,
@@ -11430,10 +11423,7 @@ static SDValue performXorCombine(SDNode *N, SelectionDAG &DAG,
11430
11423
if (DCI.isBeforeLegalizeOps())
11431
11424
return SDValue();
11432
11425
11433
- if (SDValue Cmp = foldVectorXorShiftIntoCmp(N, DAG, Subtarget))
11434
- return Cmp;
11435
-
11436
- return performIntegerAbsCombine(N, DAG);
11426
+ return foldVectorXorShiftIntoCmp(N, DAG, Subtarget);
11437
11427
}
11438
11428
11439
11429
SDValue
0 commit comments