[PATCH] D32563: Improve code placement algorithm in Reassociate pass.

David Li via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 27 15:38:26 PDT 2017


davidxl added inline comments.


================
Comment at: lib/Transforms/Scalar/Reassociate.cpp:1075
                                   SmallVectorImpl<WeakVH> &Ops){
-  if (Ops.size() == 1) return Ops.back();
-
-  Value *V1 = Ops.back();
-  Ops.pop_back();
-  Value *V2 = EmitAddTreeOfValues(I, Ops);
-  return CreateAdd(V2, V1, "tmp", I, I);
+  Value *Prev = Ops[0];
+  bool InsertToI = Prev->getNumUses() > 1;
----------------
I think you should a whole expression tree level benefit analysis instead of just looking at the sub-expression.

For instance,

for expression tree:

((a+b)+c)+d

if a has multiple uses, but b, c, d do not, it is still beneficial to shrink the live ranges of b,c and d by moving the computation closer to the definition. In the current implementation, (a+b) will be pushed closer to its consumer which makes it impossible to shrink other operands.


https://reviews.llvm.org/D32563





More information about the llvm-commits mailing list