[PATCH] D51396: [Constant Hoisting] Hoisting Constant GEP Expressions

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 29 16:27:44 PDT 2018


efriedma added inline comments.


================
Comment at: lib/Transforms/Scalar/ConstantHoisting.cpp:407
+  int Cost = 3;;
+  if (Cost > TTI->getIntImmCost(Instruction::Add, 1, Offset, PtrIntTy)) {
+    ConstCandVecType &ExprCandVec = ConstGEPCandMap[BaseGV];
----------------
zzheng wrote:
> efriedma wrote:
> > This still seems weird; we only hoist if the cost is less than 3?
> We want to hoist when cost of hoisting is smaller than cost of not-hoisting.
> 
> Currently a constant GEP whose base pointer is a GV, is lowered to a CP entry. The initial value of Cost reflects cost of loading this CP entry.
> 
> If loading from CP is always more expensive than computing it by <base + offset>, perhaps we can get rid of this if condition?
Making it unconditional is probably okay.

Well, we might not want to hoist if the offset is so small we aren't actually getting any benefit.  (e.g. loading from `[r0]`  and `[r0, #4]`  isn't really better than loading from `[r0, #8]` and `[r0, #12]`).


Repository:
  rL LLVM

https://reviews.llvm.org/D51396





More information about the llvm-commits mailing list