[PATCH] D21919: AMDGPU: Make infinite loop clear, NFC

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 30 19:42:06 PDT 2016


Is this the right fix, or is the infinite loop accidental?

> On 2016-Jun-30, at 19:40, Duncan P. N. Exon Smith via llvm-commits <llvm-commits at lists.llvm.org> wrote:
> 
> dexonsmith created this revision.
> dexonsmith added a reviewer: arsenm.
> dexonsmith added a subscriber: llvm-commits.
> Herald added a reviewer: tstellarAMD.
> Herald added subscribers: kzhuravl, arsenm.
> 
> 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).
> 
> 
> http://reviews.llvm.org/D21919
> 
> Files:
>  lib/Target/AMDGPU/AMDILCFGStructurizer.cpp
> 
> Index: lib/Target/AMDGPU/AMDILCFGStructurizer.cpp
> ===================================================================
> --- lib/Target/AMDGPU/AMDILCFGStructurizer.cpp
> +++ lib/Target/AMDGPU/AMDILCFGStructurizer.cpp
> @@ -423,7 +423,8 @@
> 
> 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:
> 
> 
> <D21919.62456.patch>_______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list