[PATCH] D139876: [LoopSimplify] Restoring the normalization of br instructions.

Dmitry Bakunevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 12:48:03 PST 2022


dbakunevich created this revision.
dbakunevich added a reviewer: mkazantsev.
Herald added a subscriber: hiraditya.
Herald added a project: All.
dbakunevich requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

As part of a particular optimization (InstCombine for example),
the situations may occur when we exit the loop on the true branch.
This transformation breaks a number of optimizations.
Therefore, it was decided to restore such instructions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139876

Files:
  llvm/lib/Transforms/Utils/LoopSimplify.cpp


Index: llvm/lib/Transforms/Utils/LoopSimplify.cpp
===================================================================
--- llvm/lib/Transforms/Utils/LoopSimplify.cpp
+++ llvm/lib/Transforms/Utils/LoopSimplify.cpp
@@ -535,6 +535,11 @@
 
           Changed = true;
         }
+        BasicBlock *TrueBB, *FalseBB;
+        using namespace PatternMatch;
+        if (match(BI, m_Br(m_Value(), TrueBB, FalseBB)) &&
+            !L->contains(TrueBB) && L->contains(FalseBB))
+          BI->swapSuccessors();
       }
 
   // Does the loop already have a preheader?  If so, don't insert one.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139876.482231.patch
Type: text/x-patch
Size: 586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221212/788dc046/attachment.bin>


More information about the llvm-commits mailing list