[llvm] [RISCV][NFC] Simplify Imm range checks (PR #170497)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 3 15:09:05 PST 2025


================
@@ -2904,7 +2904,7 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
           Ok = isUInt<5>(Imm) && (Imm > 3);
           break;
         case RISCVOp::OPERAND_UIMM5_PLUS1:
-          Ok = (isUInt<5>(Imm) && (Imm != 0)) || (Imm == 32);
+          Ok = Imm >= 1 && Imm <= 32;
----------------
topperc wrote:

> Not sure if that is any better but we couldn't we also do isUInt<5>(Imm - 1) to avoid using these constants?

You have to do `Imm != INT64_MIN && sUInt<5>(Imm - 1)` or `isUInt<5>((uint64_t)Imm - 1)` to avoid UB from signed integer wrapping on the `Imm - 1`.

https://github.com/llvm/llvm-project/pull/170497


More information about the llvm-commits mailing list