[PATCH] D63800: [NFC][PowerPC] Improve the for loop in Early Return

Zhang Kang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 25 18:35:52 PDT 2019


ZhangKang created this revision.
ZhangKang added reviewers: nemanjai, echristo, steven.zhang, hfinkel, hiraditya, jsji, efriedma.
Herald added a project: LLVM.

In `PPCEarlyReturn.cpp`

  183       for (MachineFunction::iterator I = MF.begin(); I != MF.end();) {
  184         MachineBasicBlock &B = *I++;
  185         if (processBlock(B))
  186           Changed = true;
  187       }

Above code can be improve to:

  184       for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E;) {
  185         MachineBasicBlock &B = *I++;
  186         Changed |= processBlock(B);
  187       }


https://reviews.llvm.org/D63800

Files:
  llvm/lib/Target/PowerPC/PPCEarlyReturn.cpp


Index: llvm/lib/Target/PowerPC/PPCEarlyReturn.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCEarlyReturn.cpp
+++ llvm/lib/Target/PowerPC/PPCEarlyReturn.cpp
@@ -179,11 +179,11 @@
       // nothing to do.
       if (MF.size() < 2)
         return Changed;
-
-      for (MachineFunction::iterator I = MF.begin(); I != MF.end();) {
+      
+      // We can't use a range-based for loop due to clobbering the iterator.
+      for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E;) {
         MachineBasicBlock &B = *I++;
-        if (processBlock(B))
-          Changed = true;
+        Changed |= processBlock(B);
       }
 
       return Changed;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63800.206572.patch
Type: text/x-patch
Size: 715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190626/90d8d74f/attachment.bin>


More information about the llvm-commits mailing list