Commit f49b2396 by Jim Stichnoth

Subzero: Recognize single-block loops during loop depth analysis.

BUG= none R=jpp@chromium.org Review URL: https://codereview.chromium.org/1416113007 .
parent e39d0ca2
......@@ -34,6 +34,14 @@ void LoopAnalyzer::LoopNode::incrementLoopNestDepth() {
BB->incrementLoopNestDepth();
}
bool LoopAnalyzer::LoopNode::hasSelfEdge() const {
for (CfgNode *Succ : BB->getOutEdges()) {
if (Succ == BB)
return true;
}
return false;
}
LoopAnalyzer::LoopAnalyzer(Cfg *Fn) : Func(Fn) {
const NodeList &Nodes = Func->getNodes();
......@@ -115,6 +123,8 @@ LoopAnalyzer::processNode(LoopAnalyzer::LoopNode &Node) {
// Single node means no loop in the CFG
if (LoopStack.back() == &Node) {
LoopStack.back()->setOnStack(false);
if (Node.hasSelfEdge())
LoopStack.back()->incrementLoopNestDepth();
LoopStack.back()->setDeleted();
++NumDeletedNodes;
LoopStack.pop_back();
......
......@@ -78,6 +78,7 @@ private:
bool isDeleted() const { return Deleted; }
void incrementLoopNestDepth();
bool hasSelfEdge() const;
private:
CfgNode *BB;
......
......@@ -279,3 +279,28 @@ out:
; CHECK-NEXT: out:
; CHECK-NEXT: LoopNestDepth = 0
; CHECK-LABEL: Before RMW
define internal void @test_single_block_loop(i32 %count) {
entry:
br label %body
body:
; %i = phi i32 [ 0, %entry ], [ %inc, %body ]
; A normal loop would have a phi instruction like above for the induction
; variable, but that may introduce new basic blocks due to phi edge splitting,
; so we use an alternative definition for %i to make the test more clear.
%i = add i32 %count, 1
%inc = add i32 %i, 1
%cmp = icmp slt i32 %inc, %count
br i1 %cmp, label %body, label %exit
exit:
ret void
}
; CHECK-LABEL: After loop nest depth analysis
; CHECK-NEXT: entry:
; CHECK-NEXT: LoopNestDepth = 0
; CHECK-NEXT: body:
; CHECK-NEXT: LoopNestDepth = 1
; CHECK-NEXT: exit:
; CHECK-NEXT: LoopNestDepth = 0
; CHECK-LABEL: Before RMW
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment