Skip to content

Conversation

@artagnon
Copy link
Contributor

@artagnon artagnon commented Feb 3, 2025

DenseMap::erase() doesn't invalidate the iterator.

@artagnon artagnon requested review from david-arm, fhahn and nikic February 3, 2025 12:18
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Feb 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 3, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Ramkumar Ramachandra (artagnon)

Changes

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

1 Files Affected:

  • (modified) llvm/lib/Analysis/LoopAccessAnalysis.cpp (+2-6)
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index ac8a35fbc54fb1d..7e4358dc62b1e08 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -3078,20 +3078,16 @@ const LoopAccessInfo &LoopAccessInfoManager::getInfo(Loop &L) {
   return *It->second;
 }
 void LoopAccessInfoManager::clear() {
-  SmallVector<Loop *> ToRemove;
   // Collect LoopAccessInfo entries that may keep references to IR outside the
   // analyzed loop or SCEVs that may have been modified or invalidated. At the
   // moment, that is loops requiring memory or SCEV runtime checks, as those cache
   // SCEVs, e.g. for pointer expressions.
-  for (const auto &[L, LAI] : LoopAccessInfoMap) {
+  for (const auto &[L, LAI] : make_early_inc_range(LoopAccessInfoMap)) {
     if (LAI->getRuntimePointerChecking()->getChecks().empty() &&
         LAI->getPSE().getPredicate().isAlwaysTrue())
       continue;
-    ToRemove.push_back(L);
-  }
-
-  for (Loop *L : ToRemove)
     LoopAccessInfoMap.erase(L);
+  }
 }
 
 bool LoopAccessInfoManager::invalidate(

@artagnon artagnon changed the title LAA: use make_early_inc_range to simplify code (NFC) LAA: simplifycode in LoopAccessInfoManager::clear (NFC) Feb 3, 2025
@artagnon artagnon changed the title LAA: simplifycode in LoopAccessInfoManager::clear (NFC) LAA: simplify code in LoopAccessInfoManager::clear (NFC) Feb 3, 2025
@artagnon artagnon changed the title LAA: simplify code in LoopAccessInfoManager::clear (NFC) LAA: simplify LoopAccessInfoManager::clear (NFC) Feb 3, 2025
Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,thanks

@artagnon artagnon merged commit db43dd7 into llvm:main Feb 3, 2025
8 checks passed
@artagnon artagnon deleted the laa-early-inc-iter-nfc branch February 3, 2025 16:06
@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 3, 2025

LLVM Buildbot has detected a new failure on builder openmp-offload-amdgpu-runtime running on omp-vega20-0 while building llvm at step 7 "Add check check-offload".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/15143

Here is the relevant piece of the build log for the reference
Step 7 (Add check check-offload) failure: test (failure)
******************** TEST 'libomptarget :: amdgcn-amd-amdhsa :: api/omp_host_call.c' FAILED ********************
Exit Code: 2

Command Output (stdout):
--
# RUN: at line 1
/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang -fopenmp    -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib  -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c -o /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a && /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp | /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c
# executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/clang -fopenmp -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test -I /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -L /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -nogpulib -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -Wl,-rpath,/home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib -fopenmp-targets=amdgcn-amd-amdhsa /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c -o /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./lib/libomptarget.devicertl.a
# note: command had no output on stdout or stderr
# executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/runtimes/runtimes-bins/offload/test/amdgcn-amd-amdhsa/api/Output/omp_host_call.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11
# executed command: /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c
# .---command stderr------------
# | FileCheck error: '<stdin>' is empty.
# | FileCheck command line:  /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.build/./bin/FileCheck /home/ompworker/bbot/openmp-offload-amdgpu-runtime/llvm.src/offload/test/api/omp_host_call.c
# `-----------------------------
# error: command failed with exit status: 2

--

********************


@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 3, 2025

LLVM Buildbot has detected a new failure on builder flang-aarch64-out-of-tree running on linaro-flang-aarch64-out-of-tree while building llvm at step 7 "build-flang-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/53/builds/11759

Here is the relevant piece of the build log for the reference
Step 7 (build-flang-unified-tree) failure: build (failure)
...
3266.334 [69/10/80] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-data.cpp.o
3274.470 [69/9/81] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-purity.cpp.o
3277.939 [69/8/82] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-return.cpp.o
3279.343 [69/7/83] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-io.cpp.o
3280.441 [62/13/84] Linking CXX static library lib/libFortranParser.a
3281.494 [62/12/85] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-case.cpp.o
3308.506 [62/11/86] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-call.cpp.o
3310.544 [62/10/87] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-coarray.cpp.o
3311.853 [56/15/88] Linking CXX static library lib/libFortranEvaluate.a
3321.118 [56/14/89] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-omp-structure.cpp.o
FAILED: lib/Semantics/CMakeFiles/FortranSemantics.dir/check-omp-structure.cpp.o 
/usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_flang/lib/Semantics -I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/flang/lib/Semantics -I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/flang/include -I/home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_flang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_llvm/tools/mlir/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_llvm/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/clang/include -isystem /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/build_llvm/tools/clang/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Werror -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion           -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17   -D_GNU_SOURCE -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT lib/Semantics/CMakeFiles/FortranSemantics.dir/check-omp-structure.cpp.o -MF lib/Semantics/CMakeFiles/FortranSemantics.dir/check-omp-structure.cpp.o.d -o lib/Semantics/CMakeFiles/FortranSemantics.dir/check-omp-structure.cpp.o -c /home/tcwg-buildbot/worker/flang-aarch64-out-of-tree/llvm-project/flang/lib/Semantics/check-omp-structure.cpp
../llvm-project/flang/lib/Semantics/check-omp-structure.cpp:4728:32: error: captured structured bindings are a C++20 extension [-Werror,-Wc++20-extensions]
 4728 |                   context_.Say(traitName.source,
      |                                ^
../llvm-project/flang/lib/Semantics/check-omp-structure.cpp:4721:14: note: 'traitName' declared here
 4721 |       auto &[traitName, maybeProps]{trait.t};
      |              ^
../llvm-project/flang/lib/Semantics/check-omp-structure.cpp:4735:32: error: captured structured bindings are a C++20 extension [-Werror,-Wc++20-extensions]
 4735 |                   context_.Say(traitName.source,
      |                                ^
../llvm-project/flang/lib/Semantics/check-omp-structure.cpp:4721:14: note: 'traitName' declared here
 4721 |       auto &[traitName, maybeProps]{trait.t};
      |              ^
../llvm-project/flang/lib/Semantics/check-omp-structure.cpp:4742:32: error: captured structured bindings are a C++20 extension [-Werror,-Wc++20-extensions]
 4742 |                   context_.Say(traitName.source,
      |                                ^
../llvm-project/flang/lib/Semantics/check-omp-structure.cpp:4721:14: note: 'traitName' declared here
 4721 |       auto &[traitName, maybeProps]{trait.t};
      |              ^
3 errors generated.
3337.709 [56/13/90] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-cuda.cpp.o
3348.616 [56/12/91] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-do-forall.cpp.o
3363.594 [56/11/92] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-stop.cpp.o
3365.613 [56/10/93] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-select-type.cpp.o
3369.705 [56/9/94] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/compute-offsets.cpp.o
3388.773 [56/8/95] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/check-select-rank.cpp.o
3391.454 [56/7/96] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/openmp-modifiers.cpp.o
3391.706 [56/6/97] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/program-tree.cpp.o
3395.971 [56/5/98] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/definable.cpp.o
3434.365 [56/4/99] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/data-to-inits.cpp.o
3443.949 [56/3/100] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/pointer-assignment.cpp.o
3471.810 [56/2/101] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/mod-file.cpp.o
3578.105 [56/1/102] Building CXX object lib/Semantics/CMakeFiles/FortranSemantics.dir/expression.cpp.o
ninja: build stopped: subcommand failed.

Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
DenseMap::erase() doesn't invalidate the iterator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants