[PATCH] D38415: [SimplifyIndVar] Replace IVUsers with loop invariant if possible

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 14:10:44 PDT 2017


efriedma added inline comments.


================
Comment at: lib/Transforms/Utils/SimplifyIndVar.cpp:552
 
-  if (!C)
+  if (!SE->isLoopInvariant(S, L))
     return false;
----------------
etherzhhb wrote:
> We may only want to do the replace if S is invariant of the IV's Loop, which may be different from "L" which is the innermost loop that contains the IV user
Yes; otherwise, the transform isn't doing anything useful.

We might need to call isHighCostExpansion here, so we don't generate something ridiculous?


================
Comment at: lib/Transforms/Utils/SimplifyIndVar.cpp:555
 
-  Constant *V = C->getValue();
-  // The SCEV will have a different type than the instruction if the instruction
-  // has a pointer type. Skip the replacement
-  // TODO: Replace ConstantInt Zero by ConstantPointerNull
-  if (V->getType() != I->getType())
-    return false;
+  auto *Invariant = Rewriter.expandCodeFor(S, I->getType(), I);
 
----------------
"I" is probably not the right place the put any expansion code, given it's inside the loop.


https://reviews.llvm.org/D38415





More information about the llvm-commits mailing list