Index: include/polly/CodeGen/IslNodeBuilder.h =================================================================== --- include/polly/CodeGen/IslNodeBuilder.h +++ include/polly/CodeGen/IslNodeBuilder.h @@ -262,6 +262,14 @@ /// @param NewValues A map that maps certain llvm::Values to new llvm::Values. void updateValues(ValueMapT &NewValues); + /// Return the most up-to-date version of the llvm::Value for code generation. + /// @param Original The Value to check for an up to date version. + /// @returns A remapped `Value` from ValueMap, or `Original` if no mapping + /// exists. + /// @see IslNodeBuilder::updateValues + /// @see IslNodeBuilder::ValueMap + Value *getLatestValue(Value *Original) const; + /// Generate code for a marker now. /// /// For mark nodes with an unknown name, we just forward the code generation Index: lib/CodeGen/IslNodeBuilder.cpp =================================================================== --- lib/CodeGen/IslNodeBuilder.cpp +++ lib/CodeGen/IslNodeBuilder.cpp @@ -293,7 +293,6 @@ SetVector SCEVs; struct SubtreeReferences References = { LI, SE, S, ValueMap, Values, SCEVs, getBlockGenerator()}; - for (const auto &I : IDToValue) Values.insert(I.second); @@ -325,11 +324,7 @@ // 2. test/Isl/CodeGen/OpenMP/loop-body-references-outer-values-3.ll SetVector ReplacedValues; for (Value *V : Values) { - auto It = ValueMap.find(V); - if (It == ValueMap.end()) - ReplacedValues.insert(V); - else - ReplacedValues.insert(It->second); + ReplacedValues.insert(getLatestValue(V)); } Values = ReplacedValues; } @@ -350,6 +345,13 @@ } } +Value *IslNodeBuilder::getLatestValue(Value *Original) const { + auto It = ValueMap.find(Original); + if (It == ValueMap.end()) + return Original; + return It->second; +} + void IslNodeBuilder::createUserVector(__isl_take isl_ast_node *User, std::vector &IVS, __isl_take isl_id *IteratorID, Index: lib/CodeGen/PPCGCodeGeneration.cpp =================================================================== --- lib/CodeGen/PPCGCodeGeneration.cpp +++ lib/CodeGen/PPCGCodeGeneration.cpp @@ -1413,11 +1413,7 @@ // @see IslNodeBuilder::getReferencesInSubtree SetVector ReplacedValues; for (Value *V : ValidSubtreeValues) { - auto It = ValueMap.find(V); - if (It == ValueMap.end()) - ReplacedValues.insert(V); - else - ReplacedValues.insert(It->second); + ReplacedValues.insert(getLatestValue(V)); } return std::make_pair(ReplacedValues, ValidSubtreeFunctions); } @@ -1584,9 +1580,7 @@ for (long i = 0; i < NumVars; i++) { isl_id *Id = isl_space_get_dim_id(Kernel->space, isl_dim_param, i); - Value *Val = IDToValue[Id]; - if (ValueMap.count(Val)) - Val = ValueMap[Val]; + Value *Val = getLatestValue(IDToValue[Id]); isl_id_free(Id); ArgSizes[Index] = computeSizeInBytes(Val->getType());