[PATCH] D30036: [JumpThreading] Re-enable JumpThreading for guards

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 16 02:30:50 PST 2017


mkazantsev created this revision.

JumpThreading for guards feature has been reverted at https://reviews.llvm.org/rL295200
due to the following problem: the feature used the following algorithm for detection of
diamond patters:

1. Find a block with 2 predecessors;
2. Check that these blocks have a common single parent;
3. Check that the parent's terminator is a branch instruction.

The problem is that these checks are insufficient. They may pass for a non-diamond
construction in case if those two predecessors are actually the same block. This may
happen if parent's terminator is a br (either conditional or unconditional) to a block
that ends with "switch" instruction with exactly two branches going to one block.

This patch re-enables the JumpThreading for guards and fixes this issue by adding the
check that those found predecessors are actually different blocks. This guarantees that
parent's terminator is a conditional branch with exactly 2 different successors, which
is now ensured by assertions. It also adds two more tests for this situation (with parent's
terminator being a conditional and an unconditional branch).


https://reviews.llvm.org/D30036

Files:
  include/llvm/Transforms/Scalar/JumpThreading.h
  include/llvm/Transforms/Utils/Cloning.h
  lib/Transforms/Scalar/JumpThreading.cpp
  lib/Transforms/Utils/CloneFunction.cpp
  test/Transforms/JumpThreading/guards.ll
  unittests/Transforms/Utils/Cloning.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30036.88705.patch
Type: text/x-patch
Size: 20655 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170216/dbf0cf9e/attachment.bin>


More information about the llvm-commits mailing list