[PATCH] D15093: Fix the assert in Annotate the loop in SIAnnotateControlFlow pass when the loop terminator condition is a constant.
Changpeng Fang via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 30 15:20:47 PST 2015
cfang updated this revision to Diff 41444.
cfang added a comment.
Updated based on Matt's comments.
http://reviews.llvm.org/D15093
Files:
lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
test/CodeGen/AMDGPU/si-annotate-cfg-loop-assert.ll
Index: test/CodeGen/AMDGPU/si-annotate-cfg-loop-assert.ll
===================================================================
--- /dev/null
+++ test/CodeGen/AMDGPU/si-annotate-cfg-loop-assert.ll
@@ -0,0 +1,26 @@
+; REQUIRES: asserts
+; XFAIL: *
+; RUN: llc -march=amdgcn -mcpu=kaveri < %s | FileCheck %s
+
+
+target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
+target triple = "spir64-unknown-unknown"
+
+
+; Function Attrs: norecurse nounwind uwtable
+define spir_kernel void @test(i32, i32, i32 addrspace(1)* nocapture, i32, i32, i32, i32) #0 align 2 {
+ %8 = icmp ne i32 %0, 0
+ %9 = icmp ne i32 %1, 0
+ %or.cond.i.i = and i1 %8, %9
+ br i1 %or.cond.i.i, label %.lr.ph.i.i.preheader, label %"_ZZ9test_mainvENK3$_0clEN6Kalmar5indexILi2EEE.exit"
+
+.lr.ph.i.i.preheader: ; preds = %7
+ br label %.lr.ph.i.i
+
+.lr.ph.i.i: ; preds = %.lr.ph.i.i.preheader, %.lr.ph.i.i
+ br label %.lr.ph.i.i
+
+"_ZZ9test_mainvENK3$_0clEN6Kalmar5indexILi2EEE.exit": ; preds = %7
+ ret void
+}
+
Index: lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
===================================================================
--- lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
+++ lib/Target/AMDGPU/SIAnnotateControlFlow.cpp
@@ -83,7 +83,8 @@
void insertElse(BranchInst *Term);
- Value *handleLoopCondition(Value *Cond, PHINode *Broken, llvm::Loop *L);
+ Value *handleLoopCondition(Value *Cond, PHINode *Broken,
+ llvm::Loop *L, BranchInst *Term);
void handleLoop(BranchInst *Term);
@@ -208,7 +209,7 @@
/// \brief Recursively handle the condition leading to a loop
Value *SIAnnotateControlFlow::handleLoopCondition(Value *Cond, PHINode *Broken,
- llvm::Loop *L) {
+ llvm::Loop *L, BranchInst *Term) {
// Only search through PHI nodes which are inside the loop. If we try this
// with PHI nodes that are outside of the loop, we end up inserting new PHI
@@ -232,7 +233,7 @@
}
Phi->setIncomingValue(i, BoolFalse);
- Value *PhiArg = handleLoopCondition(Incoming, Broken, L);
+ Value *PhiArg = handleLoopCondition(Incoming, Broken, L, Term);
NewPhi->addIncoming(PhiArg, From);
}
@@ -271,6 +272,11 @@
Value *Args[] = { Cond, Broken };
return CallInst::Create(IfBreak, Args, "", Insert);
+ // Insert IfBreak before TERM for constant COND.
+ } else if (isa<ConstantInt>(Cond)) {
+ Value *Args[] = { Cond, Broken };
+ return CallInst::Create(IfBreak, Args, "", Term);
+
} else {
llvm_unreachable("Unhandled loop condition!");
}
@@ -286,7 +292,7 @@
Value *Cond = Term->getCondition();
Term->setCondition(BoolTrue);
- Value *Arg = handleLoopCondition(Cond, Broken, L);
+ Value *Arg = handleLoopCondition(Cond, Broken, L, Term);
for (pred_iterator PI = pred_begin(Target), PE = pred_end(Target);
PI != PE; ++PI) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15093.41444.patch
Type: text/x-patch
Size: 3041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151130/6950db87/attachment.bin>
More information about the llvm-commits
mailing list