[PATCH] D43473: Bump iterator in for loop increment expr (NFCI)

Brian Gesiak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 19 10:01:50 PST 2018


modocache created this revision.
modocache added reviewers: rafael, davide, bkramer.

Several for loops in PromoteMemoryToRegister.cpp leave their increment
expression empty, instead incrementing the iterator within the for loop
body. I believe this is because these loops were previously implemented
as while loops; see https://reviews.llvm.org/rL188327.

Incrementing the iterator within the body of the for loop instead of
in its increment expression makes it seem like the iterator will be
modified or conditionally incremented within the loop, but that is not
the case in these loops.

Move the increment into the for loop in order to make the loops more
straightforward.

Test Plan: `check-llvm`


Repository:
  rL LLVM

https://reviews.llvm.org/D43473

Files:
  lib/Transforms/Utils/PromoteMemoryToRegister.cpp


Index: lib/Transforms/Utils/PromoteMemoryToRegister.cpp
===================================================================
--- lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -136,8 +136,8 @@
     // As we scan the uses of the alloca instruction, keep track of stores,
     // and decide whether all of the loads and stores to the alloca are within
     // the same basic block.
-    for (auto UI = AI->user_begin(), E = AI->user_end(); UI != E;) {
-      Instruction *User = cast<Instruction>(*UI++);
+    for (auto UI = AI->user_begin(), E = AI->user_end(); UI != E; UI++) {
+      Instruction *User = cast<Instruction>(*UI);
 
       if (StoreInst *SI = dyn_cast<StoreInst>(User)) {
         // Remember the basic blocks which define new values for the alloca
@@ -325,9 +325,8 @@
   // Knowing that this alloca is promotable, we know that it's safe to kill all
   // instructions except for load and store.
 
-  for (auto UI = AI->user_begin(), UE = AI->user_end(); UI != UE;) {
+  for (auto UI = AI->user_begin(), UE = AI->user_end(); UI != UE; UI++) {
     Instruction *I = cast<Instruction>(*UI);
-    ++UI;
     if (isa<LoadInst>(I) || isa<StoreInst>(I))
       continue;
 
@@ -364,8 +363,8 @@
   // Clear out UsingBlocks.  We will reconstruct it here if needed.
   Info.UsingBlocks.clear();
 
-  for (auto UI = AI->user_begin(), E = AI->user_end(); UI != E;) {
-    Instruction *UserInst = cast<Instruction>(*UI++);
+  for (auto UI = AI->user_begin(), E = AI->user_end(); UI != E; UI++) {
+    Instruction *UserInst = cast<Instruction>(*UI);
     if (!isa<LoadInst>(UserInst)) {
       assert(UserInst == OnlyStore && "Should only have load/stores");
       continue;
@@ -479,8 +478,8 @@
 
   // Walk all of the loads from this alloca, replacing them with the nearest
   // store above them, if any.
-  for (auto UI = AI->user_begin(), E = AI->user_end(); UI != E;) {
-    LoadInst *LI = dyn_cast<LoadInst>(*UI++);
+  for (auto UI = AI->user_begin(), E = AI->user_end(); UI != E; UI++) {
+    LoadInst *LI = dyn_cast<LoadInst>(*UI);
     if (!LI)
       continue;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43473.134938.patch
Type: text/x-patch
Size: 2132 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180219/187b9441/attachment.bin>


More information about the llvm-commits mailing list