[llvm] r274902 - AMDGPU: Make infinite loop clear, NFC

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 12:00:17 PDT 2016

Author: dexonsmith
Date: Fri Jul  8 14:00:17 2016
New Revision: 274902

URL: http://llvm.org/viewvc/llvm-project?rev=274902&view=rev
AMDGPU: Make infinite loop clear, NFC

Change a while loop that was checking for nullptr on an
iterator-to-pointer conversion to an infinite for loop.  Now it's clear
that the condition doesn't terminate.

The only change in behaviour is if an invalid iterator (holding nullptr)
was passed into AMDGPUCFGStructurizer::reversePredicateSetter.  There
are only two callers, and they both dereference the iterator before
sending it in, so rather than adding an early return to avoid the loop
I've just asserted (using a static_cast, to avoid an implicit conversion
to pointer).


Modified: llvm/trunk/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp?rev=274902&r1=274901&r2=274902&view=diff
--- llvm/trunk/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDILCFGStructurizer.cpp Fri Jul  8 14:00:17 2016
@@ -423,7 +423,8 @@ bool AMDGPUCFGStructurizer::needMigrateB
 void AMDGPUCFGStructurizer::reversePredicateSetter(
     MachineBasicBlock::iterator I) {
-  while (I--) {
+  assert(static_cast<MachineInstr *>(I) && "Expected valid iterator");
+  for (;; --I) {
     if (I->getOpcode() == AMDGPU::PRED_X) {
       switch (static_cast<MachineInstr *>(I)->getOperand(2).getImm()) {
       case OPCODE_IS_ZERO_INT:

More information about the llvm-commits mailing list