From cb358c5493cfb9af8cdca3d7e46876d74204d279 Mon Sep 17 00:00:00 2001 From: Sean Fertile Date: Wed, 5 Jul 2017 17:57:57 +0000 Subject: [PATCH] [PowerPC] Make sure that we remove dead PHI nodes after the PPCCTRLoops pass. Commiting on behalf of Stefan Pintilie. Differential Revision: https://reviews.llvm.org/D34829 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307180 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/PowerPC/PPCCTRLoops.cpp | 5 ++- test/CodeGen/PowerPC/ppc-ctr-dead-code.ll | 38 +++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/CodeGen/PowerPC/ppc-ctr-dead-code.ll diff --git a/lib/Target/PowerPC/PPCCTRLoops.cpp b/lib/Target/PowerPC/PPCCTRLoops.cpp index 094d3e6a61b..53f33ac1fc0 100644 --- a/lib/Target/PowerPC/PPCCTRLoops.cpp +++ b/lib/Target/PowerPC/PPCCTRLoops.cpp @@ -607,7 +607,10 @@ bool PPCCTRLoops::convertToCTRLoop(Loop *L) { // The old condition may be dead now, and may have even created a dead PHI // (the original induction variable). RecursivelyDeleteTriviallyDeadInstructions(OldCond); - DeleteDeadPHIs(CountedExitBlock); + // Run through the basic blocks of the loop and see if any of them have dead + // PHIs that can be removed. + for (auto I : L->blocks()) + DeleteDeadPHIs(I); ++NumCTRLoops; return MadeChange; diff --git a/test/CodeGen/PowerPC/ppc-ctr-dead-code.ll b/test/CodeGen/PowerPC/ppc-ctr-dead-code.ll new file mode 100644 index 00000000000..71755f722cb --- /dev/null +++ b/test/CodeGen/PowerPC/ppc-ctr-dead-code.ll @@ -0,0 +1,38 @@ +; RUN: llc < %s -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr9 -verify-machineinstrs | FileCheck %s +; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr9 -verify-machineinstrs | FileCheck %s +; RUN: llc < %s -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 -verify-machineinstrs | FileCheck %s +; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr8 -verify-machineinstrs | FileCheck %s + +; Function Attrs: norecurse nounwind readonly +define signext i32 @limit_loop(i32 signext %iters, i32* nocapture readonly %vec, i32 signext %limit) local_unnamed_addr { +entry: + %cmp5 = icmp sgt i32 %iters, 0 + br i1 %cmp5, label %for.body.preheader, label %cleanup + +for.body.preheader: ; preds = %entry + %0 = sext i32 %iters to i64 + br label %for.body + +for.cond: ; preds = %for.body + %cmp = icmp slt i64 %indvars.iv.next, %0 + br i1 %cmp, label %for.body, label %cleanup + +for.body: ; preds = %for.body.preheader, %for.cond + %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.cond ] + %arrayidx = getelementptr inbounds i32, i32* %vec, i64 %indvars.iv + %1 = load i32, i32* %arrayidx, align 4 + %cmp1 = icmp slt i32 %1, %limit + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 + br i1 %cmp1, label %for.cond, label %cleanup + +cleanup: ; preds = %for.body, %for.cond, %entry + %2 = phi i32 [ 0, %entry ], [ 0, %for.cond ], [ 1, %for.body ] + ret i32 %2 +; CHECK-LABEL: limit_loop +; CHECK: mtctr +; CHECK-NOT: addi {{[0-9]+}}, {{[0-9]+}}, 1 +; CHECK: bdnz +; CHECK: blr +} + + -- 2.49.0