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(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) { 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 +} +