From 97c3c32372bb8478c53ab9469585c7c6e531cbd2 Mon Sep 17 00:00:00 2001 From: Sergei Barannikov Date: Sat, 14 Dec 2024 13:58:23 +0300 Subject: [TableGen][SystemZ] Correctly check the range of a leaf immediate (#119931) The "Size >= 32" check probably dates back to when TableGen integers were 32-bit. Delete it and simplify code by using `isInt`/`isUInt`. --- llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp') diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp index 10f6590..31bf9a9 100644 --- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp @@ -2463,20 +2463,16 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) { // Can only check for types of a known size if (VT == MVT::iPTR) continue; - unsigned Size = MVT(VT).getFixedSizeInBits(); - // Make sure that the value is representable for this type. - if (Size >= 32) - continue; + // Check that the value doesn't use more bits than we have. It must // either be a sign- or zero-extended equivalent of the original. - int64_t SignBitAndAbove = II->getValue() >> (Size - 1); - if (SignBitAndAbove == -1 || SignBitAndAbove == 0 || - SignBitAndAbove == 1) - continue; - - TP.error("Integer value '" + Twine(II->getValue()) + - "' is out of range for type '" + getEnumName(VT) + "'!"); - break; + unsigned Width = MVT(VT).getFixedSizeInBits(); + int64_t Val = II->getValue(); + if (!isIntN(Width, Val) && !isUIntN(Width, Val)) { + TP.error("Integer value '" + Twine(Val) + + "' is out of range for type '" + getEnumName(VT) + "'!"); + break; + } } return MadeChange; } -- cgit v1.1