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

Diego Novillo dnovillo at google.com
Thu May 7 08:13:09 PDT 2015


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.

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.

Diego.



More information about the llvm-commits mailing list