[llvm] r284898 - Fix map insertion that is elided in release build.

David L. Jones via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 21 16:30:40 PDT 2016


Author: dlj
Date: Fri Oct 21 18:30:39 2016
New Revision: 284898

URL: http://llvm.org/viewvc/llvm-project?rev=284898&view=rev
Log:
Fix map insertion that is elided in release build.

The assert() macro doesn't actually execute its body in Release builds, so using
it to check cache invariants requires that the insertion be outside of the
assert() statement. This change does that, and also makes sure to return the
actual map contents.

Modified:
    llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h

Modified: llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h?rev=284898&r1=284897&r2=284898&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h (original)
+++ llvm/trunk/include/llvm/Analysis/ScalarEvolutionExpressions.h Fri Oct 21 18:30:39 2016
@@ -558,10 +558,10 @@ namespace llvm {
       auto It = RewriteResults.find(S);
       if (It != RewriteResults.end())
         return It->second;
-      auto *Result = SCEVVisitor<SC, const SCEV *>::visit(S);
-      assert(RewriteResults.insert({S, Result}).second &&
-             "Should insert a new entry");
-      return Result;
+      auto* Visited = SCEVVisitor<SC, const SCEV *>::visit(S);
+      auto Result = RewriteResults.try_emplace(S, Visited);
+      assert(Result.second && "Should insert a new entry");
+      return Result.first->second;
     }
 
     const SCEV *visitConstant(const SCEVConstant *Constant) {




More information about the llvm-commits mailing list