[PATCH] D124159: [SimplifyCFG] Thread branches on same condition in more cases (PR54980)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 21 03:55:03 PDT 2022


nikic created this revision.
nikic added reviewers: spatel, lebedev.ri, fhahn.
Herald added a subscriber: hiraditya.
Herald added a project: All.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

SimplifyCFG implements basic jump threading, if a branch is performed on a phi node with constant operands. However, InstCombine canonicalizes such phis to the condition value of a previous branch, if possible. SimplifyCFG does support this as well, but only in the very limited case where the same condition is used in a direct predecessor -- notably, this does not include the common diamond pattern (i.e. two consecutive if/elses on the same condition).

This patch extends the code to look back a limited number of blocks to find a branch on the same value, rather than only looking at the direct predecessor.

Fixes https://github.com/llvm/llvm-project/issues/54980.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D124159

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/test/CodeGen/AArch64/arm64-andCmpBrToTBZ.ll
  llvm/test/Transforms/GVNSink/sink-common-code.ll
  llvm/test/Transforms/SimplifyCFG/X86/sink-common-code.ll
  llvm/test/Transforms/SimplifyCFG/jump-threading.ll
  llvm/test/Transforms/SimplifyCFG/wc-widen-block.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124159.424140.patch
Type: text/x-patch
Size: 7910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220421/f8666395/attachment.bin>


More information about the llvm-commits mailing list