diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index c27bf82157393..63a85faf344c4 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -4035,12 +4035,13 @@ static SDValue getAArch64Cmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, break; case ISD::SETULE: case ISD::SETUGT: { - assert(!C.isAllOnes() && "C should not be -1 here"); - APInt CPlusOne = C + 1; - if (isLegalCmpImmed(CPlusOne) || - (NumImmForC > numberOfInstrToLoadImm(CPlusOne))) { - CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; - RHS = DAG.getConstant(CPlusOne, DL, VT); + if (!C.isAllOnes()) { + APInt CPlusOne = C + 1; + if (isLegalCmpImmed(CPlusOne) || + (NumImmForC > numberOfInstrToLoadImm(CPlusOne))) { + CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; + RHS = DAG.getConstant(CPlusOne, DL, VT); + } } break; } diff --git a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp index 2abe0dd0bbdc2..6025f1c9f5f4e 100644 --- a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerLowering.cpp @@ -639,8 +639,10 @@ tryAdjustICmpImmAndPred(Register RHS, CmpInst::Predicate P, // x ule c => x ult c + 1 // x ugt c => s uge c + 1 // - assert(C != (Size == 32 ? UINT32_MAX : UINT64_MAX) && - "C should not be -1 here!"); + // When c is not the largest possible unsigned integer. + if ((Size == 32 && static_cast(C) == UINT32_MAX) || + (Size == 64 && C == UINT64_MAX)) + return std::nullopt; P = (P == CmpInst::ICMP_ULE) ? CmpInst::ICMP_ULT : CmpInst::ICMP_UGE; C += 1; break;