From 411fa4c0dfe11b262564560066f3db1440f78b34 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Fri, 12 Jul 2019 20:03:34 +0000 Subject: [SystemZ] Fix addcarry of addcarry of const carry (PR42606) This fixes https://bugs.llvm.org/show_bug.cgi?id=42606 by extending D64213. Instead of only checking if the carry comes from a matching operation, we now check the full chain of carries. Otherwise we might custom lower the outermost addcarry, but then generically legalize an inner addcarry. Differential Revision: https://reviews.llvm.org/D64658 llvm-svn: 365949 --- llvm/lib/Target/SystemZ/SystemZISelLowering.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Target/SystemZ/SystemZISelLowering.cpp') diff --git a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp index f5323a0ee06..78820f511ab 100644 --- a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp +++ b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp @@ -3459,6 +3459,18 @@ SDValue SystemZTargetLowering::lowerXALUO(SDValue Op, return DAG.getNode(ISD::MERGE_VALUES, DL, N->getVTList(), Result, SetCC); } +static bool isAddCarryChain(SDValue Carry) { + while (Carry.getOpcode() == ISD::ADDCARRY) + Carry = Carry.getOperand(2); + return Carry.getOpcode() == ISD::UADDO; +} + +static bool isSubBorrowChain(SDValue Carry) { + while (Carry.getOpcode() == ISD::SUBCARRY) + Carry = Carry.getOperand(2); + return Carry.getOpcode() == ISD::USUBO; +} + // Lower ADDCARRY/SUBCARRY nodes. SDValue SystemZTargetLowering::lowerADDSUBCARRY(SDValue Op, SelectionDAG &DAG) const { @@ -3481,7 +3493,7 @@ SDValue SystemZTargetLowering::lowerADDSUBCARRY(SDValue Op, switch (Op.getOpcode()) { default: llvm_unreachable("Unknown instruction!"); case ISD::ADDCARRY: - if (Carry.getOpcode() != ISD::UADDO && Carry.getOpcode() != ISD::ADDCARRY) + if (!isAddCarryChain(Carry)) return SDValue(); BaseOp = SystemZISD::ADDCARRY; @@ -3489,7 +3501,7 @@ SDValue SystemZTargetLowering::lowerADDSUBCARRY(SDValue Op, CCMask = SystemZ::CCMASK_LOGICAL_CARRY; break; case ISD::SUBCARRY: - if (Carry.getOpcode() != ISD::USUBO && Carry.getOpcode() != ISD::SUBCARRY) + if (!isSubBorrowChain(Carry)) return SDValue(); BaseOp = SystemZISD::SUBCARRY; -- cgit v1.2.3