]> granicus.if.org Git - llvm/commitdiff
[NFC][PowerPC] Improve the for loop in Early Return
authorKang Zhang <shkzhang@cn.ibm.com>
Thu, 27 Jun 2019 03:39:09 +0000 (03:39 +0000)
committerKang Zhang <shkzhang@cn.ibm.com>
Thu, 27 Jun 2019 03:39:09 +0000 (03:39 +0000)
Summary:

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 improved to:
```
184       for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E;) {
185         MachineBasicBlock &B = *I++;
186         Changed |= processBlock(B);
187       }
```

Reviewed By: hfinkel

Differential Revision: https://reviews.llvm.org/D63800

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364496 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPCEarlyReturn.cpp

index 6c08bcde1b3e0d0c46c9a5b87e7289f5c9ba48ec..aa5d830b549ed2079db63c4241487e45d9cf90cc 100644 (file)
@@ -179,11 +179,11 @@ public:
       // 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;