[llvm-commits] [llvm] r121674 - in /llvm/trunk: lib/Transforms/Utils/SimplifyCFG.cpp test/Transforms/SimplifyCFG/switch_create.ll

Frits van Bommel fvbommel at gmail.com
Mon Dec 13 02:34:43 PST 2010


On Mon, Dec 13, 2010 at 4:43 AM, Chris Lattner <sabre at nondot.org> wrote:
> Author: lattner
> Date: Sun Dec 12 21:43:57 2010
> New Revision: 121674
>
> URL: http://llvm.org/viewvc/llvm-project?rev=121674&view=rev
> Log:
> Fix my previous patch to handle a degenerate case that the llvm-gcc
> bootstrap buildbot tripped over.
> +  // Ok, the block is reachable from the default dest.  If the constant we're
> +  // comparing exists in one of the other edges, then we can constant fold ICI
> +  // and zap it.
> +  if (SI->findCaseValue(Cst) != 0) {

This should probably also make sure the successor for that case isn't
equal to BB. (Yes, this is an even *more* degenerate case since BB is
the default destination of the switch, but it's valid IR...)

> +    Value *V;
> +    if (ICI->getPredicate() == ICmpInst::ICMP_EQ)
> +      V = ConstantInt::getFalse(BB->getContext());
> +    else
> +      V = ConstantInt::getTrue(BB->getContext());
> +
> +    ICI->replaceAllUsesWith(V);
> +    ICI->eraseFromParent();
> +    // BB is now empty, so it is likely to simplify away.
> +    return SimplifyCFG(BB) | true;
> +  }
> +

By the way, the "if (SI->getDefaultDest() != BB)" just before this
doesn't seem to handle the case where multiple cases jump to BB.




More information about the llvm-commits mailing list