Extend EarlyCSE to handle basic cases from JumpThreading and CVP
authorPhilip Reames <listmail@philipreames.com>
Fri, 22 May 2015 23:53:24 +0000 (23:53 +0000)
committerPhilip Reames <listmail@philipreames.com>
Fri, 22 May 2015 23:53:24 +0000 (23:53 +0000)
commite00c0df2c427ed0a21362a4e3f6439557b488838
tree23bfdee6dcaf90bd41a9269561652f8b9db7aee2
parent12baade49832cdeb0fcc44dfe24f08b946c77763
Extend EarlyCSE to handle basic cases from JumpThreading and CVP

This patch extends EarlyCSE to take advantage of the information that a controlling branch gives us about the value of a Value within this and dominated basic blocks. If the current block has a single predecessor with a controlling branch, we can infer what the branch condition must have been to execute this block. The actual change to support this is downright simple because EarlyCSE's existing scoped hash table logic deals with most of the complexity around merging.

The patch actually implements two optimizations.
1) The first is analogous to JumpThreading in that it enables EarlyCSE's CSE handling to fold branches which are exactly redundant due to a previous branch to branches on constants. (It doesn't actually replace the branch or change the CFG.) This is pretty clearly a win since it enables substantial CFG simplification before we start trying to inline.
2) The second is analogous to CVP in that it exploits the knowledge gained to replace dominated *uses* of the original value. EarlyCSE does not otherwise reason about specific uses, so this is the more arguable one. It does enable further simplication and constant folding within the rest of the visit by EarlyCSE.

In both cases, the added code only handles the easy dominance based case of each optimization. The general case is deferred to the existing passes.

Differential Revision: http://reviews.llvm.org/D9763

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238071 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Transforms/Utils/Local.h
lib/Transforms/Scalar/EarlyCSE.cpp
lib/Transforms/Scalar/GVN.cpp
lib/Transforms/Utils/Local.cpp
test/Transforms/EarlyCSE/conditional.ll [new file with mode: 0644]
test/Transforms/EarlyCSE/edge.ll [new file with mode: 0644]