Reapply [SCCP] Directly remove non-feasible edges
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 21 Jul 2020 19:26:30 +0000 (21:26 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 25 Jul 2020 12:52:35 +0000 (14:52 +0200)
commitad16e71c953c92dbb4ffe9581c4e31a4cde70ccf
tree3c6476b75b0ef71bed3bc3165759cc239e3b17b6
parentb5e14d78f16960ebb94f0a22e2a8c10f421f8757
Reapply [SCCP] Directly remove non-feasible edges

Reapply with DTU update moved after CFG update, which is a
requirement of the API.

-----

Non-feasible control-flow edges are currently removed by replacing
the branch condition with a constant and then calling
ConstantFoldTerminator. This happens in a rather roundabout manner,
by inspecting the users (effectively: predecessors) of unreachable
blocks, and further complicated by the need to explicitly materialize
the condition for "forced" edges. I would like to extend SCCP to
discard switch conditions that are non-feasible based on range
information, but this is incompatible with the current approach
(as there is no single constant we could use.)

Instead, this patch explicitly removes non-feasible edges. It
currently only needs to handle the case where there is a single
feasible edge. The llvm_unreachable() branch will need to be
implemented for the aforementioned switch improvement.

Differential Revision: https://reviews.llvm.org/D84264
llvm/lib/Transforms/Scalar/SCCP.cpp
llvm/test/Transforms/SCCP/conditions-ranges.ll
llvm/test/Transforms/SCCP/domtree-update.ll [new file with mode: 0644]
llvm/test/Transforms/SCCP/predicateinfo-cond.ll
llvm/test/Transforms/SCCP/resolvedundefsin-tracked-fn.ll
llvm/test/Transforms/SCCP/switch-constantfold-crash.ll
llvm/test/Transforms/SCCP/switch.ll
llvm/test/Transforms/SCCP/widening.ll