[llvm] r214642 - [SimplifyCFG] fix accessing deleted PHINodes in switch-to-table conversion.

Hans Wennborg hwennborg at google.com
Thu Aug 7 11:36:25 PDT 2014


On Sat, Aug 2, 2014 at 4:41 PM, Manman Ren <manman.ren at gmail.com> wrote:
> Author: mren
> Date: Sat Aug  2 18:41:54 2014
> New Revision: 214642
>
> URL: http://llvm.org/viewvc/llvm-project?rev=214642&view=rev
> Log:
> [SimplifyCFG] fix accessing deleted PHINodes in switch-to-table conversion.
>
> When we have a covered lookup table, make sure we don't delete PHINodes that
> are cached in PHIs.

Thanks for fixing this!

> Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=214642&r1=214641&r2=214642&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Sat Aug  2 18:41:54 2014
> @@ -3830,7 +3830,10 @@ static bool SwitchToLookupTable(SwitchIn
>    const bool GeneratingCoveredLookupTable = MaxTableSize == TableSize;
>    if (GeneratingCoveredLookupTable) {
>      Builder.CreateBr(LookupBB);
> -    SI->getDefaultDest()->removePredecessor(SI->getParent());
> +    // We cached PHINodes in PHIs, to avoid accessing deleted PHINodes later,
> +    // do not delete PHINodes here.
> +    SI->getDefaultDest()->removePredecessor(SI->getParent(),
> +                                            true/*DontDeleteUselessPHIs*/);

I was trying to figure out why the PHI gets removed here, since it has
other predecessors besides the DefaultDest, but I see from your test
case that it's not because of the removed predecessor, but because the
phi gets folded to a single value as a side-effect.

Thanks,
Hans



More information about the llvm-commits mailing list