[llvm] [TableGen][NFC] Use templated std::clamp (PR #179400)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 2 22:12:55 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-tablegen

Author: Sam Elliott (lenary)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/179400.diff


3 Files Affected:

- (modified) llvm/test/TableGen/generic-tables-instruction.td (+2-2) 
- (modified) llvm/test/TableGen/generic-tables.td (+1-1) 
- (modified) llvm/utils/TableGen/SearchableTableEmitter.cpp (+3-4) 


``````````diff
diff --git a/llvm/test/TableGen/generic-tables-instruction.td b/llvm/test/TableGen/generic-tables-instruction.td
index 7b99784f2d73a..3d98333b32922 100644
--- a/llvm/test/TableGen/generic-tables-instruction.td
+++ b/llvm/test/TableGen/generic-tables-instruction.td
@@ -18,7 +18,7 @@ def Arch : Target { let InstructionSet = ArchInstrInfo; }
 // A contiguous primary (Instruction) key should get a direct lookup instead of
 // binary search.
 // CHECK: const MyInstr *getCustomEncodingHelper(unsigned Opcode) {
-// CHECK: if ((unsigned)Opcode != std::clamp((unsigned)Opcode, (unsigned)B, (unsigned)D))
+// CHECK: if ((unsigned)Opcode != std::clamp<unsigned>(Opcode, B, D))
 // CHECK:   return nullptr;
 // CHECK:   auto Table = ArrayRef(InstrTable);
 // CHECK:   size_t Idx = Opcode - B;
@@ -54,7 +54,7 @@ def InstrTable : GenericTable {
 //
 // Verify contiguous check for SearchIndex.
 // const MyInfoEntry *getTable2ByValue(uint8_t Value) {
-// CHECK:   if ((uint8_t)Value != std::clamp((uint8_t)Value, (uint8_t)0xB, (uint8_t)0xD))
+// CHECK:   if ((uint8_t)Value != std::clamp<uint8_t>(Value, 0xB, 0xD))
 // CHECK:    return nullptr;
 // CHECK:  auto Table = ArrayRef(Index);
 // CHECK:  size_t Idx = Value - 0xB;
diff --git a/llvm/test/TableGen/generic-tables.td b/llvm/test/TableGen/generic-tables.td
index 8638740a8e565..6b72a3e807e7d 100644
--- a/llvm/test/TableGen/generic-tables.td
+++ b/llvm/test/TableGen/generic-tables.td
@@ -113,7 +113,7 @@ def lookupBTableByNameAndFlag : SearchIndex {
 // CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind);
 // CHECK-LABEL: GET_CTable_IMPL
 // CHECK: const CEntry *lookupCEntryByEncoding(uint16_t Encoding) {
-// CHECK:   if ((uint16_t)Encoding != std::clamp((uint16_t)Encoding, (uint16_t)0xA, (uint16_t)0xF))
+// CHECK:   if ((uint16_t)Encoding != std::clamp<uint16_t>(Encoding, 0xA, 0xF))
 // CHECK:     return nullptr;
 
 // CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind) {
diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index 0dc8c92a5a37a..88aa6bf8e9242 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -430,10 +430,9 @@ void SearchableTableEmitter::emitLookupFunction(const GenericTable &Table,
     std::string LastRepr = primaryRepresentation(
         Index.Loc, Field, IndexRows.back()->getValueInit(Field.Name));
     std::string TS =
-        '(' + searchableFieldType(Table, Index, Field, TypeInStaticStruct) +
-        ')';
-    OS << "  if (" << TS << Field.Name << " != std::clamp(" << TS << Field.Name
-       << ", " << TS << FirstRepr << ", " << TS << LastRepr << "))\n";
+        searchableFieldType(Table, Index, Field, TypeInStaticStruct);
+    OS << "  if ((" << TS << ")" << Field.Name << " != std::clamp<" << TS
+       << ">(" << Field.Name << ", " << FirstRepr << ", " << LastRepr << "))\n";
     OS << "    return nullptr;\n\n";
 
     if (IsContiguous && !Index.EarlyOut) {

``````````

</details>


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


More information about the llvm-commits mailing list