[PATCH] D46162: [PowerPC] Don't transform to CTR loop if the decrement branch instr. would end up in a different loop

Nemanja Ivanovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 26 19:30:43 PDT 2018


nemanjai added inline comments.


================
Comment at: lib/Target/PowerPC/PPCCTRLoops.cpp:579
+    if (LI->getLoopFor(*I) != L)
+      continue;
+
----------------
efriedma wrote:
> The actual condition you need to check is whether the branch executes exactly once per iteration.
> 
> For most code, this check is equivalent, but it's possible to have an irreducible "loop" which is not an LLVM Loop.
Sorry if this is a naive question, but would adding a check that this loop's header dominates the exit block suffice for such a case?

I don't really know what an irreducible loop looks like, but with this question, I'm making the assumption that for such a loop, there would have to be a path to the exit block that doesn't go through the header. Of course, if this assumption is wrong, please correct me.


================
Comment at: test/CodeGen/PowerPC/no-ctr-loop-if-exit-in-nested-loop.ll:1-4
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mcpu=pwr8 -mtriple=powerpc64le-unknown-unknown \
+; RUN:   -verify-machineinstrs < %s | FileCheck %s
+define hidden fastcc void @gen_bitlen() {
----------------
chandlerc wrote:
> I'm really worried that this test is overreduced.
> 
> I think you should craft an IR test that directly forms the pattern you describe where an outer loop has an exiting block shared with an inner loop, but the trip count can only be computed for the outer loop.
> 
> I'd also encourage you to not have any undef in the branches. Instead, you really just want to have a "real" (if minimal) loop structure.
Yeah, I took the easy approach of unleashing `bugpoint` on the original test case. I'll reduce it manually to keep the original structure in the test.


Repository:
  rL LLVM

https://reviews.llvm.org/D46162





More information about the llvm-commits mailing list