[llvm] [TableGen] Avoid repeated hash lookups (NFC) (PR #107669)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 6 23:36:15 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-globalisel

Author: Kazu Hirata (kazutakahirata)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp (+3-8) 


``````````diff
diff --git a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
index 0f8f1cce817002..b97b87e2117507 100644
--- a/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp
@@ -1696,9 +1696,8 @@ bool CombineRuleBuilder::emitPatFragMatchPattern(
     DenseSet<const Pattern *> &SeenPats) {
   auto StackTrace = PrettyStackTraceEmit(RuleDef, &PFP);
 
-  if (SeenPats.contains(&PFP))
+  if (!SeenPats.insert(&PFP).second)
     return true;
-  SeenPats.insert(&PFP);
 
   const auto &PF = PFP.getPatFrag();
 
@@ -1919,11 +1918,9 @@ bool CombineRuleBuilder::emitInstructionApplyPattern(
     StringMap<unsigned> &OperandToTempRegID) {
   auto StackTrace = PrettyStackTraceEmit(RuleDef, &P);
 
-  if (SeenPats.contains(&P))
+  if (!SeenPats.insert(&P).second)
     return true;
 
-  SeenPats.insert(&P);
-
   // First, render the uses.
   for (auto &Op : P.named_operands()) {
     if (Op.isDef())
@@ -2188,11 +2185,9 @@ bool CombineRuleBuilder::emitCodeGenInstructionMatchPattern(
     OperandMapperFnRef OperandMapper) {
   auto StackTrace = PrettyStackTraceEmit(RuleDef, &P);
 
-  if (SeenPats.contains(&P))
+  if (!SeenPats.insert(&P).second)
     return true;
 
-  SeenPats.insert(&P);
-
   IM.addPredicate<InstructionOpcodeMatcher>(&P.getInst());
   declareInstExpansion(CE, IM, P.getName());
 

``````````

</details>


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


More information about the llvm-commits mailing list