[all-commits] [llvm/llvm-project] 514bc0: [SimplifyCFG] FoldBranchToCommonDest(): properly h...

Roman Lebedev via All-commits all-commits at lists.llvm.org
Tue Mar 23 07:38:11 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 514bc01ca3b9f97945dd49aa40e01922fed0e41d
      https://github.com/llvm/llvm-project/commit/514bc01ca3b9f97945dd49aa40e01922fed0e41d
  Author: Roman Lebedev <lebedev.ri at gmail.com>
  Date:   2021-03-23 (Tue, 23 Mar 2021)

  Changed paths:
    M llvm/lib/Transforms/Utils/SimplifyCFG.cpp
    M llvm/test/Transforms/SimplifyCFG/fold-branch-to-common-dest.ll

  Log Message:
  -----------
  [SimplifyCFG] FoldBranchToCommonDest(): properly handle same-block external uses (PR49510/PR49689)

We clone bonus instructions to the end of the predecessor block,
and then use `SSAUpdater::RewriteUseAfterInsertions()`.
But that only deals with the cases where the use-to-be-rewritten
are either in different block from the def, or come after the def.

But in some loop cases, the external use may be in the beginning of
predecessor block, before the newly cloned bonus instruction.
`SSAUpdater::RewriteUseAfterInsertions()` does not deal with that.
Notably, the external use can't happen to be both in the same block
and *after* the newly-cloned instruction, because of the fold preconditions.

To properly handle these cases, when the use is in the same block,
we should instead use `SSAUpdater::RewriteUse()`.
TBN, they do the same thing for PHI users.

Fixes https://bugs.llvm.org/show_bug.cgi?id=49510
Likely Fixes https://bugs.llvm.org/show_bug.cgi?id=49689




More information about the All-commits mailing list