[llvm] r236684 - [JumpThreading] Simplify comparisons when simplifying branches

Philip Reames listmail at philipreames.com
Thu May 7 15:33:34 PDT 2015



On 05/07/2015 08:13 AM, Diego Novillo wrote:
> On Wed, May 6, 2015 at 5:19 PM, Philip Reames <listmail at philipreames.com> wrote:
>
>> --- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Wed May  6 19:19:14 2015
>> @@ -791,6 +791,17 @@ bool JumpThreading::ProcessBlock(BasicBl
>>             CondBr->getSuccessor(ToRemove)->removePredecessor(BB, true);
>>             BranchInst::Create(CondBr->getSuccessor(ToKeep), CondBr);
>>             CondBr->eraseFromParent();
>> +          if (CondCmp->use_empty())
>> +            CondCmp->eraseFromParent();
>> +          else if (CondCmp->getParent() == BB) {
>> +            // If the fact we just learned is true for all uses of the
>> +            // condition, replace it with a constant value
>> +            auto *CI = Baseline == LazyValueInfo::True ?
>> +              ConstantInt::getTrue(CondCmp->getType()) :
>> +              ConstantInt::getFalse(CondCmp->getType());
>> +            CondCmp->replaceAllUsesWith(CI);
>> +            CondCmp->eraseFromParent();
>> +          }
> This in fact works for both a true branch and an else branch, right?
> The comment seems to imply that it only works for true values, but the
> code works for both. Or maybe I'm misreading it.
You're right, the comment is confusing.  Will fix.
>
> Will this trigger folding in if-trees inside the dominator tree that
> this is being propagated?  So, if I had another if-then-else inside
> that could be folded due to the comparison of the parent, for
> instance.
This particular optimization isn't changing the CFG.  You might have a 
branch on a constant after this has run, but the CFG is still the same.  
As such, the dom tree should remain valid.
>
> Diego.




More information about the llvm-commits mailing list