[llvm] [AMDGPU][FixIrreducible][UnifyLoopExits] Support callbr with inline-asm (PR #149308)
Robert Imschweiler via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 25 08:30:13 PDT 2025
================
@@ -342,3 +345,76 @@ std::pair<BasicBlock *, bool> ControlFlowHub::finalize(
return {FirstGuardBlock, true};
}
+
+// Check if the given cycle is disjoint with the cycle of the given basic block.
+// If the basic block does not belong to any cycle, this is regarded as
+// disjoint, too.
+static bool disjointWithBlock(CycleInfo *CI, Cycle *C, BasicBlock *BB) {
+ Cycle *CC = CI->getCycle(BB);
+ if (!CC)
+ return true;
+ Cycle *CommonC = CI->getSmallestCommonCycle(C, CC);
+ return CommonC != C && CommonC != CC;
+}
+
+// Check if the given loop is disjoint with the loop of the given basic block.
+// If the basic block does not belong to any loop, this is regarded as
+// disjoint, too.
+static bool disjointWithBlock(LoopInfo *LI, Loop *L, BasicBlock *BB) {
+ Loop *LL = LI->getLoopFor(BB);
+ return LL && !L->contains(LL) && !LL->contains(L);
+}
+
+template <typename TI, typename T>
+static void updateCycleLoopInfo(TI *LCI, bool AttachToCallBr,
+ BasicBlock *CallBrBlock,
+ BasicBlock *CallBrTarget, BasicBlock *Succ) {
+ static_assert(std::is_same_v<TI, CycleInfo> || std::is_same_v<TI, LoopInfo>,
+ "type must be CycleInfo or LoopInfo");
+ if (!LCI)
+ return;
+
+ T *LC;
+ if constexpr (std::is_same_v<TI, CycleInfo>)
+ LC = LCI->getCycle(AttachToCallBr ? CallBrBlock : Succ);
+ else
+ LC = LCI->getLoopFor(AttachToCallBr ? CallBrBlock : Succ);
+ if (!LC)
+ return;
+
+ // Check if the cycles/loops are disjoint. In that case, we do not add the
+ // intermediate target to any cycle/loop.
+ if (AttachToCallBr && disjointWithBlock(LCI, LC, Succ))
----------------
ro-i wrote:
You're right, thanks (see my newest commits)
https://github.com/llvm/llvm-project/pull/149308
More information about the llvm-commits
mailing list