diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index f49c5011607f9..5e3b42fdc7aba 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -5368,9 +5368,10 @@ SDValue RISCVTargetLowering::LowerOperation(SDValue Op, if (isa(RHS)) { int64_t Imm = cast(RHS)->getSExtValue(); if (Imm != 0 && isInt<12>((uint64_t)Imm + 1)) { - // X > -1 should have been replaced with false. - assert((CCVal != ISD::SETUGT || Imm != -1) && - "Missing canonicalization"); + // If this is an unsigned compare and the constant is -1, incrementing + // the constant would change behavior. The result should be false. + if (CCVal == ISD::SETUGT && Imm == -1) + return DAG.getConstant(0, DL, VT); // Using getSetCCSwappedOperands will convert SET(U)GT->SET(U)LT. CCVal = ISD::getSetCCSwappedOperands(CCVal); SDValue SetCC = DAG.getSetCC( diff --git a/llvm/test/CodeGen/RISCV/pr64503.ll b/llvm/test/CodeGen/RISCV/pr64503.ll new file mode 100644 index 0000000000000..921187144ffd8 --- /dev/null +++ b/llvm/test/CodeGen/RISCV/pr64503.ll @@ -0,0 +1,37 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2 +; RUN: llc < %s -mtriple=riscv32 | FileCheck %s + +define i1 @f(i64 %LGV1) { +; CHECK-LABEL: f: +; CHECK: # %bb.0: +; CHECK-NEXT: li a0, 1 +; CHECK-NEXT: beqz a1, .LBB0_2 +; CHECK-NEXT: # %bb.1: +; CHECK-NEXT: snez a0, a1 +; CHECK-NEXT: xori a0, a0, 1 +; CHECK-NEXT: .LBB0_2: +; CHECK-NEXT: ret + %B1 = xor i64 %LGV1, %LGV1 + %B2 = srem i64 1, %B1 + %B5 = lshr i64 1, %B2 + %C4 = icmp ule i64 %LGV1, %B5 + ret i1 %C4 +} + +define i64 @g(ptr %A, i64 %0) { +; CHECK-LABEL: g: +; CHECK: # %bb.0: +; CHECK-NEXT: li a0, 1 +; CHECK-NEXT: beqz a2, .LBB1_2 +; CHECK-NEXT: # %bb.1: +; CHECK-NEXT: slti a0, a2, 1 +; CHECK-NEXT: .LBB1_2: +; CHECK-NEXT: sb a0, 0(zero) +; CHECK-NEXT: ret + store i64 poison, ptr %A, align 4 + %LGV1 = load i64, ptr %A, align 4 + %B1 = ashr i64 1, %LGV1 + %C = icmp sle i64 %0, %B1 + store i1 %C, ptr null, align 1 + ret i64 %LGV1 +}