From 45944e7cf45915eb2a0a2fae24e3396fc91dfc22 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Mon, 25 Jul 2022 15:42:42 -0700 Subject: [PATCH] [RISCV] Refactor translateSetCCForBranch to prepare for D130508. NFC. D130508 handles more constants than just 1 or -1. We need to extract the constant instead of relying isOneConstant or isAllOnesConstant. --- llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 34 +++++++++++++-------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 146605782e9a..baa19e81e436 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -1406,18 +1406,28 @@ static void translateSetCCForBranch(const SDLoc &DL, SDValue &LHS, SDValue &RHS, } } - // Convert X > -1 to X >= 0. - if (CC == ISD::SETGT && isAllOnesConstant(RHS)) { - RHS = DAG.getConstant(0, DL, RHS.getValueType()); - CC = ISD::SETGE; - return; - } - // Convert X < 1 to 0 >= X. - if (CC == ISD::SETLT && isOneConstant(RHS)) { - RHS = LHS; - LHS = DAG.getConstant(0, DL, RHS.getValueType()); - CC = ISD::SETGE; - return; + if (auto *RHSC = dyn_cast(RHS)) { + int64_t C = RHSC->getSExtValue(); + switch (CC) { + default: break; + case ISD::SETGT: + // Convert X > -1 to X >= 0. + if (C == -1) { + RHS = DAG.getConstant(0, DL, RHS.getValueType()); + CC = ISD::SETGE; + return; + } + break; + case ISD::SETLT: + // Convert X < 1 to 0 <= X. + if (C == 1) { + RHS = LHS; + LHS = DAG.getConstant(0, DL, RHS.getValueType()); + CC = ISD::SETGE; + return; + } + break; + } } switch (CC) {