[PATCH] If a conditional branch jumps to the same target, remove the condition

Philip Reames listmail at philipreames.com
Tue Mar 10 15:12:28 PDT 2015


@Hal - Unless I'm missing something, this is already handled in 
ConstantFoldTerminator.

     if (Dest2 == Dest1) {       // Conditional branch to same location?
       // This branch matches something like this:
       //     br bool %cond, label %Dest, label %Dest
       // and changes it into:  br label %Dest

       // Let the basic block know that we are letting go of one copy of it.
       assert(BI->getParent() && "Terminator not inserted in block!");
       Dest1->removePredecessor(BI->getParent());

       // Replace the conditional branch with an unconditional one.
       Builder.CreateBr(Dest1);
       Value *Cond = BI->getCondition();
       BI->eraseFromParent();
       if (DeleteDeadConditions)
         RecursivelyDeleteTriviallyDeadInstructions(Cond, TLI);
       return true;
     }

Given this, I plan to submit as is.

On 03/10/2015 01:43 PM, hfinkel at anl.gov wrote:
> LGTM. But, could you also please fix llvm::ConstantFoldTerminator in lib/Transforms/Utils/Local.cpp so that it handles the undef condition and transforms the branch with the undef condition into an unconditional branch. If we don't want to do that, then we should just pick true/false here instead of using undef.
>
>
> http://reviews.llvm.org/D8220
>
> EMAIL PREFERENCES
>    http://reviews.llvm.org/settings/panel/emailpreferences/
>
>




More information about the llvm-commits mailing list