[PATCH] D13974: [IndVarSimplify] Rewrite loop exit values with their initial values from loop preheader

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 27 11:07:14 PDT 2015


sanjoy added inline comments.

================
Comment at: lib/Transforms/Scalar/IndVarSimplify.cpp:747
@@ +746,3 @@
+
+        // All non-instructions are loop-invariant.
+        if (auto *CondInst = dyn_cast<Instruction>(Cond))
----------------
chenli wrote:
> sanjoy wrote:
> > ]I'd change this to `isLoopInvariant` for now -- `make LoopInvariant` may hoist arithmetic etc. over control flow and this could be a regression e.g. in cases like
> > 
> > 
> > ```
> > for ( ... )
> >   if (rare_condition) {
> >     int x = loop_invariant * 3;
> >     if (x == 42) then exit;
> >   }
> > ```
> > 
> > hoisting `loop_invariant * 3` to the loop preheader will be a net regression.
> > 
> > Sorry for not bringing this up earlier.
> > 
> > Also, note that both `isLoopInvariant` and `makeLoopInvariant` take a `Value` so you don't need to manually cast to an `Instruction`.
> By regression, do you mean by register pressure?
Register pressure also, but I was trying to say you'll just compute values that you don't need to compute (e.g. in the above example if `rare_condition` is always `false` at runtime then the multiplication in the loop preheader was useless).


http://reviews.llvm.org/D13974





More information about the llvm-commits mailing list