[llvm] d3b3940 - [ConstraintElim] Use try_emplace to improve code (NFC) (#178186)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 27 06:13:44 PST 2026


Author: Ramkumar Ramachandra
Date: 2026-01-27T14:13:39Z
New Revision: d3b3940a71d63190f49db730af14dd4f333c11f1

URL: https://github.com/llvm/llvm-project/commit/d3b3940a71d63190f49db730af14dd4f333c11f1
DIFF: https://github.com/llvm/llvm-project/commit/d3b3940a71d63190f49db730af14dd4f333c11f1.diff

LOG: [ConstraintElim] Use try_emplace to improve code (NFC) (#178186)

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index ba48359336d41..9a743b95a2a6d 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -728,11 +728,11 @@ ConstraintInfo::getConstraint(CmpInst::Predicate Pred, Value *Op0, Value *Op1,
     auto V2I = Value2Index.find(V);
     if (V2I != Value2Index.end())
       return V2I->second;
-    auto Insert =
-        NewIndexMap.insert({V, Value2Index.size() + NewVariables.size() + 1});
-    if (Insert.second)
+    auto [It, Inserted] = NewIndexMap.try_emplace(
+        V, Value2Index.size() + NewVariables.size() + 1);
+    if (Inserted)
       NewVariables.push_back(V);
-    return Insert.first->second;
+    return It->second;
   };
 
   // Make sure all variables have entries in Value2Index or NewVariables.
@@ -1726,7 +1726,7 @@ void ConstraintInfo::addFactImpl(CmpInst::Predicate Pred, Value *A, Value *B,
   SmallVector<Value *, 2> ValuesToRelease;
   auto &Value2Index = getValue2Index(R.IsSigned);
   for (Value *V : NewVariables) {
-    Value2Index.insert({V, Value2Index.size() + 1});
+    Value2Index.try_emplace(V, Value2Index.size() + 1);
     ValuesToRelease.push_back(V);
   }
 


        


More information about the llvm-commits mailing list