[PATCH] D52232: [IPSCCP] Fix a problem with removing labels in a switch with undef condition

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 18 07:15:35 PDT 2018


bjope created this revision.
bjope added reviewers: efriedma, fhahn, davide.

Before removing basic blocks that ipsccp has considered as dead
all uses of the basic block label must be removed. That is done
by calling ConstantFoldTerminator on the users. An exception
is when the branch condition is an undef value. In such
scenarios ipsccp is using some internal assumptions regarding
which edge in the control flow that should remain, while
ConstantFoldTerminator don't know how to fold the terminator.

The problem addressed here is related to ConstantFoldTerminator's
ability to rewrite a 'switch' into a conditional 'br'. In such
situations ConstantFoldTerminator returns true indicating that
the terminator has been rewritten. However, ipsccp treated the
true value as if the edge to the dead basic block had been
removed. So the code for resolving an undef branch condition
did not trigger, and we ended up with assertion that there were
uses remaining when deleting the basic block.

For ipsccp it is important that the original terminator is kept
untouched by ConstantFoldTerminator when branching on undef values.
Otherwise the logic for which edge that should remain in case of
undef conditions will be messed up.
The solution is to add a parameter to ConstantFoldTerminator
to optionally restrict the folding to leave the terminator untouched
unless it can be folded into an unconditional branch.


Repository:
  rL LLVM

https://reviews.llvm.org/D52232

Files:
  include/llvm/Transforms/Utils/Local.h
  lib/Transforms/Scalar/SCCP.cpp
  lib/Transforms/Utils/Local.cpp
  test/Transforms/SCCP/switch-undef-constantfoldterminator.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52232.165972.patch
Type: text/x-patch
Size: 5702 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180918/931b141f/attachment.bin>


More information about the llvm-commits mailing list