[PATCH] D139780: [AMDGPU] Annotate control flow on visited blocks
Anshil Gandhi via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 10 22:49:42 PST 2022
gandhi21299 updated this revision to Diff 481897.
gandhi21299 added a comment.
refactored patch
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D139780/new/
https://reviews.llvm.org/D139780
Files:
llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
llvm/test/CodeGen/AMDGPU/si-annotate-nested-control-flows.ll
Index: llvm/test/CodeGen/AMDGPU/si-annotate-nested-control-flows.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AMDGPU/si-annotate-nested-control-flows.ll
@@ -0,0 +1,40 @@
+; RUN: opt -mtriple=amdgcn-- -S -structurizecfg -si-annotate-control-flow %s | FileCheck %s
+
+define void @nested_inf_loop(i1 %0, i1 %1) {
+; CHECK-LABEL: define void @nested_inf_loop(
+; CHECK-NEXT: BB:
+; CHECK-NEXT: br label %BB1
+; CHECK: BB1: ; preds = %BB3, %BB
+; CHECK-NEXT: %2 = call { i1, i64 } @llvm.amdgcn.if.i64(i1 %0)
+; CHECK-NEXT: %3 = extractvalue { i1, i64 } %2, 0
+; CHECK-NEXT: %4 = extractvalue { i1, i64 } %2, 1
+; CHECK-NEXT: br i1 %3, label %BB3, label %BB2
+; CHECK: BB2: ; preds = %BB1
+; CHECK-NEXT: call void @llvm.amdgcn.end.cf.i64(i64 %4)
+; CHECK-NEXT: br label %BB4
+; CHECK: BB4: ; preds = %BB4, %BB2
+; CHECK-NEXT: %phi.broken = phi i64 [ %5, %BB4 ], [ 0, %BB2 ]
+; CHECK-NEXT: %5 = call i64 @llvm.amdgcn.if.break.i64(i1 %1, i64 %phi.broken)
+; CHECK-NEXT: %6 = call i1 @llvm.amdgcn.loop.i64(i64 %5)
+; CHECK-NEXT: br i1 %6, label %BB4.BB3_crit_edge, label %BB4
+; CHECK: BB4.BB3_crit_edge: ; preds = %BB4
+; CHECK-NEXT: call void @llvm.amdgcn.end.cf.i64(i64 %5)
+; CHECK-NEXT: br label %BB3
+; CHECK: BB3: ; preds = %BB4.BB3_crit_edge, %BB1
+; CHECK-NEXT: br label %BB1
+;
+BB:
+ br label %BB1
+
+BB1:
+ br i1 %0, label %BB3, label %BB2
+
+BB2:
+ br label %BB4
+
+BB4:
+ br i1 %1, label %BB3, label %BB4
+
+BB3:
+ br label %BB1
+}
Index: llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
+++ llvm/lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
@@ -334,6 +334,7 @@
/// Annotate the control flow with intrinsics so the backend can
/// recognize if/then/else and loops.
bool SIAnnotateControlFlow::runOnFunction(Function &F) {
+
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
DA = &getAnalysis<LegacyDivergenceAnalysis>();
@@ -350,7 +351,6 @@
if (!Term || Term->isUnconditional()) {
if (isTopOfStack(BB))
Changed |= closeControlFlow(BB);
-
continue;
}
@@ -358,8 +358,12 @@
if (isTopOfStack(BB))
Changed |= closeControlFlow(BB);
- if (DT->dominates(Term->getSuccessor(1), BB))
- Changed |= handleLoop(Term);
+ if (DT->dominates(Term->getSuccessor(1), BB)) {
+ if (handleLoop(Term) && I.nodeVisited(Stack.back().first)) {
+ Changed = true;
+ closeControlFlow(Stack.back().first);
+ }
+ }
continue;
}
@@ -373,7 +377,6 @@
Changed |= closeControlFlow(BB);
}
-
Changed |= openIf(Term);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139780.481897.patch
Type: text/x-patch
Size: 3046 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221211/184bcb6a/attachment.bin>
More information about the llvm-commits
mailing list