[llvm] [SimpleLoopUnswitch] Allow trivial unswitch when exit LCSSA is a header PHI (PR #222962)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 13 00:35:04 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
index 594544f61..07e07dd71 100644
--- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
+++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
@@ -261,10 +261,9 @@ static void replaceLoopInvariantUses(const Loop &L, Value *Invariant,
///
/// If \p UsedHeaderPHI is non-null, an incoming value that is a PHI in the
/// loop header is accepted too. *UsedHeaderPHI is set to true if that happens.
-static bool areLoopExitPHIsTrivial(const Loop &L,
- const BasicBlock &ExitingBB,
- const BasicBlock &ExitBB,
- bool *UsedHeaderPHI = nullptr) {
+static bool areLoopExitPHIsTrivial(const Loop &L, const BasicBlock &ExitingBB,
+ const BasicBlock &ExitBB,
+ bool *UsedHeaderPHI = nullptr) {
for (const Instruction &I : ExitBB) {
auto *PN = dyn_cast<PHINode>(&I);
if (!PN)
@@ -663,8 +662,8 @@ static bool unswitchTrivialBranch(Loop &L, CondBrInst &BI, DominatorTree &DT,
// header PHI. Those incomings are repaired after unswitching.
// Branch always dominates the latch as guaranteed by the caller.
bool TrivialFromHeader = false;
- if (!ModifiedBranch && !areLoopExitPHIsTrivial(
- L, *ParentBB, *LoopExitBB, &TrivialFromHeader)) {
+ if (!ModifiedBranch &&
+ !areLoopExitPHIsTrivial(L, *ParentBB, *LoopExitBB, &TrivialFromHeader)) {
LLVM_DEBUG(dbgs() << " Loop exit PHI's aren't loop-invariant!\n");
return false;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/222962
More information about the llvm-commits
mailing list