[PATCH] Extend EarlyCSE to handle basic cases from JumpThreading and CVP

Philip Reames listmail at philipreames.com
Wed May 13 15:20:48 PDT 2015


Hi hfinkel, apilipenko, sanjoy, nlewycky,

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.  
- 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.  
- 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.  

I believe both optimizations are worth adding, but I'm open to being convinced that the second should either be removed, or done differently.

http://reviews.llvm.org/D9763

Files:
  lib/Transforms/Scalar/EarlyCSE.cpp
  test/Transforms/EarlyCSE/conditional.ll

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9763.25737.patch
Type: text/x-patch
Size: 4671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150513/78b380e3/attachment.bin>


More information about the llvm-commits mailing list