Skip to content

Commit cc883e8

Browse files
committed
Revert "[PowerPC] Deprecate uses of ISD::ADDC/ISD::ADDE/ISD::SUBC/ISD::SUBE (llvm#133155)"
This reverts commit 1a540c3.
1 parent a0aa5f8 commit cc883e8

33 files changed

+435
-718
lines changed

llvm/include/llvm/CodeGen/LivePhysRegs.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ void addLiveIns(MachineBasicBlock &MBB, const LivePhysRegs &LiveRegs);
195195
void computeAndAddLiveIns(LivePhysRegs &LiveRegs,
196196
MachineBasicBlock &MBB);
197197

198-
/// Check if physical register \p Reg is used after \p MBI.
199-
bool isPhysRegUsedAfter(Register Reg, MachineBasicBlock::iterator MBI);
200-
201198
/// Convenience function for recomputing live-in's for a MBB. Returns true if
202199
/// any changes were made.
203200
static inline bool recomputeLiveIns(MachineBasicBlock &MBB) {

llvm/lib/CodeGen/LivePhysRegs.cpp

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -338,27 +338,3 @@ void llvm::computeAndAddLiveIns(LivePhysRegs &LiveRegs,
338338
computeLiveIns(LiveRegs, MBB);
339339
addLiveIns(MBB, LiveRegs);
340340
}
341-
342-
// Returns true if `Reg` is used after this iterator in the rest of the
343-
// basic block or any successors of the basic block.
344-
bool llvm::isPhysRegUsedAfter(Register Reg, MachineBasicBlock::iterator MBI) {
345-
assert(Reg.isPhysical() && "Apply to physical register only");
346-
347-
MachineBasicBlock *MBB = MBI->getParent();
348-
// Scan forward through BB for a use/def of Reg
349-
for (const MachineInstr &MI : llvm::make_range(std::next(MBI), MBB->end())) {
350-
if (MI.readsRegister(Reg, /*TRI=*/nullptr))
351-
return true;
352-
// If we found a def, we can stop searching.
353-
if (MI.definesRegister(Reg, /*TRI=*/nullptr))
354-
return false;
355-
}
356-
357-
// If we hit the end of the block, check whether Reg is live into a
358-
// successor.
359-
for (MachineBasicBlock *Succ : MBB->successors())
360-
if (Succ->isLiveIn(Reg))
361-
return true;
362-
363-
return false;
364-
}

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 55 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "llvm/ADT/StringRef.h"
3737
#include "llvm/CodeGen/CallingConvLower.h"
3838
#include "llvm/CodeGen/ISDOpcodes.h"
39-
#include "llvm/CodeGen/LivePhysRegs.h"
4039
#include "llvm/CodeGen/MachineBasicBlock.h"
4140
#include "llvm/CodeGen/MachineFrameInfo.h"
4241
#include "llvm/CodeGen/MachineFunction.h"
@@ -198,11 +197,6 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
198197
}
199198

200199
setOperationAction(ISD::UADDO, RegVT, Custom);
201-
setOperationAction(ISD::USUBO, RegVT, Custom);
202-
203-
// PowerPC uses addo_carry,subo_carry to propagate carry.
204-
setOperationAction(ISD::UADDO_CARRY, RegVT, Custom);
205-
setOperationAction(ISD::USUBO_CARRY, RegVT, Custom);
206200

207201
// On P10, the default lowering generates better code using the
208202
// setbc instruction.
@@ -272,6 +266,15 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
272266
setIndexedStoreAction(ISD::PRE_INC, MVT::f64, Legal);
273267
}
274268

269+
// PowerPC uses ADDC/ADDE/SUBC/SUBE to propagate carry.
270+
const MVT ScalarIntVTs[] = { MVT::i32, MVT::i64 };
271+
for (MVT VT : ScalarIntVTs) {
272+
setOperationAction(ISD::ADDC, VT, Legal);
273+
setOperationAction(ISD::ADDE, VT, Legal);
274+
setOperationAction(ISD::SUBC, VT, Legal);
275+
setOperationAction(ISD::SUBE, VT, Legal);
276+
}
277+
275278
if (Subtarget.useCRBits()) {
276279
setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
277280

@@ -1861,14 +1864,6 @@ const char *PPCTargetLowering::getTargetNodeName(unsigned Opcode) const {
18611864
return "PPCISD::SETBC";
18621865
case PPCISD::SETBCR:
18631866
return "PPCISD::SETBCR";
1864-
case PPCISD::ADDC:
1865-
return "PPCISD::ADDC";
1866-
case PPCISD::ADDE:
1867-
return "PPCISD::ADDE";
1868-
case PPCISD::SUBC:
1869-
return "PPCISD::SUBC";
1870-
case PPCISD::SUBE:
1871-
return "PPCISD::SUBE";
18721867
}
18731868
return nullptr;
18741869
}
@@ -12265,74 +12260,43 @@ SDValue PPCTargetLowering::LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const {
1226512260
llvm_unreachable("ERROR:Should return for all cases within swtich.");
1226612261
}
1226712262

12268-
static SDValue ConvertCarryValueToCarryFlag(EVT SumType, SDValue Value,
12269-
SelectionDAG &DAG,
12270-
const PPCSubtarget &STI) {
12271-
SDLoc DL(Value);
12272-
if (STI.useCRBits())
12273-
Value = DAG.getNode(ISD::SELECT, DL, SumType, Value,
12274-
DAG.getConstant(1, DL, SumType),
12275-
DAG.getConstant(0, DL, SumType));
12276-
else
12277-
Value = DAG.getZExtOrTrunc(Value, DL, SumType);
12278-
SDValue Sum = DAG.getNode(PPCISD::ADDC, DL, DAG.getVTList(SumType, MVT::i32),
12279-
Value, DAG.getAllOnesConstant(DL, SumType));
12280-
return Sum.getValue(1);
12281-
}
12263+
SDValue PPCTargetLowering::LowerUaddo(SDValue Op, SelectionDAG &DAG) const {
12264+
// Default to target independent lowering if there is a logical user of the
12265+
// carry-bit.
12266+
for (SDNode *U : Op->users()) {
12267+
if (U->getOpcode() == ISD::SELECT)
12268+
return SDValue();
12269+
if (ISD::isBitwiseLogicOp(U->getOpcode())) {
12270+
for (unsigned i = 0, ie = U->getNumOperands(); i != ie; ++i) {
12271+
if (U->getOperand(i).getOpcode() != ISD::UADDO &&
12272+
U->getOperand(i).getOpcode() != ISD::MERGE_VALUES)
12273+
return SDValue();
12274+
}
12275+
}
12276+
}
12277+
SDValue LHS = Op.getOperand(0);
12278+
SDValue RHS = Op.getOperand(1);
12279+
SDLoc dl(Op);
1228212280

12283-
static SDValue ConvertCarryFlagToCarryValue(EVT SumType, SDValue Flag,
12284-
EVT CarryType, SelectionDAG &DAG,
12285-
const PPCSubtarget &STI) {
12286-
SDLoc DL(Flag);
12287-
SDValue Zero = DAG.getConstant(0, DL, SumType);
12288-
SDValue Carry = DAG.getNode(
12289-
PPCISD::ADDE, DL, DAG.getVTList(SumType, MVT::i32), Zero, Zero, Flag);
12290-
if (STI.useCRBits())
12291-
return DAG.getSetCC(DL, CarryType, Carry, Zero, ISD::SETNE);
12292-
return DAG.getZExtOrTrunc(Carry, DL, CarryType);
12293-
}
12281+
// Default to target independent lowering for special cases handled there.
12282+
if (isOneConstant(RHS) || isAllOnesConstant(RHS))
12283+
return SDValue();
1229412284

12295-
SDValue PPCTargetLowering::LowerADDSUBO(SDValue Op, SelectionDAG &DAG) const {
12285+
EVT VT = Op.getNode()->getValueType(0);
1229612286

12297-
SDLoc DL(Op);
12298-
SDNode *N = Op.getNode();
12299-
EVT VT = N->getValueType(0);
12300-
EVT CarryType = N->getValueType(1);
12301-
unsigned Opc = N->getOpcode();
12302-
bool IsAdd = Opc == ISD::UADDO;
12303-
Opc = IsAdd ? PPCISD::ADDC : PPCISD::SUBC;
12304-
SDValue Sum = DAG.getNode(Opc, DL, DAG.getVTList(VT, MVT::i32),
12305-
N->getOperand(0), N->getOperand(1));
12306-
SDValue Carry = ConvertCarryFlagToCarryValue(VT, Sum.getValue(1), CarryType,
12307-
DAG, Subtarget);
12308-
if (!IsAdd)
12309-
Carry = DAG.getNode(ISD::XOR, DL, CarryType, Carry,
12310-
DAG.getConstant(1UL, DL, CarryType));
12311-
return DAG.getNode(ISD::MERGE_VALUES, DL, N->getVTList(), Sum, Carry);
12312-
}
12313-
12314-
SDValue PPCTargetLowering::LowerADDSUBO_CARRY(SDValue Op,
12315-
SelectionDAG &DAG) const {
12316-
SDLoc DL(Op);
12317-
SDNode *N = Op.getNode();
12318-
unsigned Opc = N->getOpcode();
12319-
EVT VT = N->getValueType(0);
12320-
EVT CarryType = N->getValueType(1);
12321-
SDValue CarryOp = N->getOperand(2);
12322-
bool IsAdd = Opc == ISD::UADDO_CARRY;
12323-
Opc = IsAdd ? PPCISD::ADDE : PPCISD::SUBE;
12324-
if (!IsAdd)
12325-
CarryOp = DAG.getNode(ISD::XOR, DL, CarryOp.getValueType(), CarryOp,
12326-
DAG.getAllOnesConstant(DL, CarryOp.getValueType()));
12327-
CarryOp = ConvertCarryValueToCarryFlag(VT, CarryOp, DAG, Subtarget);
12328-
SDValue Sum = DAG.getNode(Opc, DL, DAG.getVTList(VT, MVT::i32),
12329-
Op.getOperand(0), Op.getOperand(1), CarryOp);
12330-
CarryOp = ConvertCarryFlagToCarryValue(VT, Sum.getValue(1), CarryType, DAG,
12331-
Subtarget);
12332-
if (!IsAdd)
12333-
CarryOp = DAG.getNode(ISD::XOR, DL, CarryOp.getValueType(), CarryOp,
12334-
DAG.getConstant(1UL, DL, CarryOp.getValueType()));
12335-
return DAG.getNode(ISD::MERGE_VALUES, DL, N->getVTList(), Sum, CarryOp);
12287+
SDValue ADDC;
12288+
SDValue Overflow;
12289+
SDVTList VTs = Op.getNode()->getVTList();
12290+
12291+
ADDC = DAG.getNode(ISD::ADDC, dl, DAG.getVTList(VT, MVT::Glue), LHS, RHS);
12292+
Overflow = DAG.getNode(ISD::ADDE, dl, DAG.getVTList(VT, MVT::Glue),
12293+
DAG.getConstant(0, dl, VT), DAG.getConstant(0, dl, VT),
12294+
ADDC.getValue(1));
12295+
SDValue OverflowTrunc =
12296+
DAG.getNode(ISD::TRUNCATE, dl, Op.getNode()->getValueType(1), Overflow);
12297+
SDValue Res =
12298+
DAG.getNode(ISD::MERGE_VALUES, dl, VTs, ADDC.getValue(0), OverflowTrunc);
12299+
return Res;
1233612300
}
1233712301

1233812302
SDValue PPCTargetLowering::LowerSSUBO(SDValue Op, SelectionDAG &DAG) const {
@@ -12363,8 +12327,8 @@ SDValue PPCTargetLowering::LowerSSUBO(SDValue Op, SelectionDAG &DAG) const {
1236312327
///
1236412328
SDValue PPCTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
1236512329
switch (Op.getOpcode()) {
12366-
default:
12367-
llvm_unreachable("Wasn't expecting to be able to lower this!");
12330+
default: llvm_unreachable("Wasn't expecting to be able to lower this!");
12331+
case ISD::UADDO: return LowerUaddo(Op, DAG);
1236812332
case ISD::FPOW: return lowerPow(Op, DAG);
1236912333
case ISD::FSIN: return lowerSin(Op, DAG);
1237012334
case ISD::FCOS: return lowerCos(Op, DAG);
@@ -12457,12 +12421,6 @@ SDValue PPCTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
1245712421
return LowerATOMIC_LOAD_STORE(Op, DAG);
1245812422
case ISD::IS_FPCLASS:
1245912423
return LowerIS_FPCLASS(Op, DAG);
12460-
case ISD::UADDO:
12461-
case ISD::USUBO:
12462-
return LowerADDSUBO(Op, DAG);
12463-
case ISD::UADDO_CARRY:
12464-
case ISD::USUBO_CARRY:
12465-
return LowerADDSUBO_CARRY(Op, DAG);
1246612424
}
1246712425
}
1246812426

@@ -13545,11 +13503,6 @@ PPCTargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
1354513503
F->insert(It, copy0MBB);
1354613504
F->insert(It, sinkMBB);
1354713505

13548-
if (isPhysRegUsedAfter(PPC::CARRY, MI.getIterator())) {
13549-
copy0MBB->addLiveIn(PPC::CARRY);
13550-
sinkMBB->addLiveIn(PPC::CARRY);
13551-
}
13552-
1355313506
// Set the call frame size on entry to the new basic blocks.
1355413507
// See https://reviews.llvm.org/D156113.
1355513508
unsigned CallFrameSize = TII->getCallFrameSizeAt(MI);
@@ -16402,21 +16355,6 @@ static bool isStoreConditional(SDValue Intrin, unsigned &StoreWidth) {
1640216355
return true;
1640316356
}
1640416357

16405-
static SDValue DAGCombineAddc(SDNode *N,
16406-
llvm::PPCTargetLowering::DAGCombinerInfo &DCI) {
16407-
if (N->getOpcode() == PPCISD::ADDC && N->hasAnyUseOfValue(1)) {
16408-
// (ADDC (ADDE 0, 0, C), -1) -> C
16409-
SDValue LHS = N->getOperand(0);
16410-
SDValue RHS = N->getOperand(1);
16411-
if (LHS->getOpcode() == PPCISD::ADDE &&
16412-
isNullConstant(LHS->getOperand(0)) &&
16413-
isNullConstant(LHS->getOperand(1)) && isAllOnesConstant(RHS)) {
16414-
return DCI.CombineTo(N, SDValue(N, 0), LHS->getOperand(2));
16415-
}
16416-
}
16417-
return SDValue();
16418-
}
16419-
1642016358
SDValue PPCTargetLowering::PerformDAGCombine(SDNode *N,
1642116359
DAGCombinerInfo &DCI) const {
1642216360
SelectionDAG &DAG = DCI.DAG;
@@ -17205,8 +17143,6 @@ SDValue PPCTargetLowering::PerformDAGCombine(SDNode *N,
1720517143
}
1720617144
case ISD::BUILD_VECTOR:
1720717145
return DAGCombineBuildVector(N, DCI);
17208-
case PPCISD::ADDC:
17209-
return DAGCombineAddc(N, DCI);
1721017146
}
1721117147

1721217148
return SDValue();
@@ -17260,16 +17196,6 @@ void PPCTargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
1726017196
Known.Zero = 0xFFFF0000;
1726117197
break;
1726217198
}
17263-
case PPCISD::ADDE: {
17264-
if (Op.getResNo() == 0) {
17265-
// (0|1), _ = ADDE 0, 0, CARRY
17266-
SDValue LHS = Op.getOperand(0);
17267-
SDValue RHS = Op.getOperand(1);
17268-
if (isNullConstant(LHS) && isNullConstant(RHS))
17269-
Known.Zero = ~1ULL;
17270-
}
17271-
break;
17272-
}
1727317199
case ISD::INTRINSIC_WO_CHAIN: {
1727417200
switch (Op.getConstantOperandVal(0)) {
1727517201
default: break;
@@ -18539,8 +18465,7 @@ static SDValue combineADDToADDZE(SDNode *N, SelectionDAG &DAG,
1853918465
return SDValue();
1854018466

1854118467
SDLoc DL(N);
18542-
EVT CarryType = Subtarget.useCRBits() ? MVT::i1 : MVT::i32;
18543-
SDVTList VTs = DAG.getVTList(MVT::i64, CarryType);
18468+
SDVTList VTs = DAG.getVTList(MVT::i64, MVT::Glue);
1854418469
SDValue Cmp = RHS.getOperand(0);
1854518470
SDValue Z = Cmp.getOperand(0);
1854618471
auto *Constant = cast<ConstantSDNode>(Cmp.getOperand(1));
@@ -18558,14 +18483,11 @@ static SDValue combineADDToADDZE(SDNode *N, SelectionDAG &DAG,
1855818483
SDValue Add = DAG.getNode(ISD::ADD, DL, MVT::i64, Z,
1855918484
DAG.getConstant(NegConstant, DL, MVT::i64));
1856018485
SDValue AddOrZ = NegConstant != 0 ? Add : Z;
18561-
SDValue Addc =
18562-
DAG.getNode(ISD::UADDO_CARRY, DL, DAG.getVTList(MVT::i64, CarryType),
18563-
AddOrZ, DAG.getAllOnesConstant(DL, MVT::i64),
18564-
DAG.getConstant(0, DL, CarryType));
18565-
return DAG.getNode(ISD::UADDO_CARRY, DL, VTs, LHS,
18566-
DAG.getConstant(0, DL, MVT::i64),
18486+
SDValue Addc = DAG.getNode(ISD::ADDC, DL, DAG.getVTList(MVT::i64, MVT::Glue),
18487+
AddOrZ, DAG.getAllOnesConstant(DL, MVT::i64));
18488+
return DAG.getNode(ISD::ADDE, DL, VTs, LHS, DAG.getConstant(0, DL, MVT::i64),
1856718489
SDValue(Addc.getNode(), 1));
18568-
}
18490+
}
1856918491
case ISD::SETEQ: {
1857018492
// when C == 0
1857118493
// --> addze X, (subfic Z, 0).carry
@@ -18576,15 +18498,11 @@ static SDValue combineADDToADDZE(SDNode *N, SelectionDAG &DAG,
1857618498
SDValue Add = DAG.getNode(ISD::ADD, DL, MVT::i64, Z,
1857718499
DAG.getConstant(NegConstant, DL, MVT::i64));
1857818500
SDValue AddOrZ = NegConstant != 0 ? Add : Z;
18579-
SDValue Subc =
18580-
DAG.getNode(ISD::USUBO_CARRY, DL, DAG.getVTList(MVT::i64, CarryType),
18581-
DAG.getConstant(0, DL, MVT::i64), AddOrZ,
18582-
DAG.getConstant(0, DL, CarryType));
18583-
SDValue Invert = DAG.getNode(ISD::XOR, DL, CarryType, Subc.getValue(1),
18584-
DAG.getConstant(1UL, DL, CarryType));
18585-
return DAG.getNode(ISD::UADDO_CARRY, DL, VTs, LHS,
18586-
DAG.getConstant(0, DL, MVT::i64), Invert);
18587-
}
18501+
SDValue Subc = DAG.getNode(ISD::SUBC, DL, DAG.getVTList(MVT::i64, MVT::Glue),
18502+
DAG.getConstant(0, DL, MVT::i64), AddOrZ);
18503+
return DAG.getNode(ISD::ADDE, DL, VTs, LHS, DAG.getConstant(0, DL, MVT::i64),
18504+
SDValue(Subc.getNode(), 1));
18505+
}
1858818506
}
1858918507

1859018508
return SDValue();

llvm/lib/Target/PowerPC/PPCISelLowering.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,6 @@ namespace llvm {
161161
SRA,
162162
SHL,
163163

164-
/// These nodes represent PPC arithmetic operations with carry.
165-
ADDC,
166-
ADDE,
167-
SUBC,
168-
SUBE,
169-
170164
/// FNMSUB - Negated multiply-subtract instruction.
171165
FNMSUB,
172166

@@ -1286,6 +1280,7 @@ namespace llvm {
12861280
SDValue LowerGlobalTLSAddressLinux(SDValue Op, SelectionDAG &DAG) const;
12871281
SDValue LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const;
12881282
SDValue LowerJumpTable(SDValue Op, SelectionDAG &DAG) const;
1283+
SDValue LowerUaddo(SDValue Op, SelectionDAG &DAG) const;
12891284
SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG) const;
12901285
SDValue LowerSSUBO(SDValue Op, SelectionDAG &DAG) const;
12911286
SDValue LowerINIT_TRAMPOLINE(SDValue Op, SelectionDAG &DAG) const;
@@ -1321,8 +1316,6 @@ namespace llvm {
13211316
SDValue LowerBSWAP(SDValue Op, SelectionDAG &DAG) const;
13221317
SDValue LowerATOMIC_CMP_SWAP(SDValue Op, SelectionDAG &DAG) const;
13231318
SDValue LowerIS_FPCLASS(SDValue Op, SelectionDAG &DAG) const;
1324-
SDValue LowerADDSUBO_CARRY(SDValue Op, SelectionDAG &DAG) const;
1325-
SDValue LowerADDSUBO(SDValue Op, SelectionDAG &DAG) const;
13261319
SDValue lowerToLibCall(const char *LibCallName, SDValue Op,
13271320
SelectionDAG &DAG) const;
13281321
SDValue lowerLibCallBasedOnType(const char *LibCallFloatName,

0 commit comments

Comments
 (0)