[PATCH] D11051: Extend LICM to hoist loop invariant GEP out

hfinkel at anl.gov hfinkel at anl.gov
Sat Jul 25 12:15:43 PDT 2015


hfinkel added a comment.

You need to address this:

> If you have the inbounds tag, then the transformation can still be performed, although inbounds has to dropped in most cases, since otherwise we would need to prove that the intermediate results don't overflow.


By either restricting to GEPs that don't have inbounds, or dropping inbounds after performing the transformation. Specifically, I think what Nuno is saying is that, for example, if we have:

  ptr = (p + o) + c

and both are inbounds, then we know that (p + o) does not overflow, and specifically is no more than one byte past the end of the object to which p belongs. We also know that (p + o) + c offers the same guarantees. We don't, however, know that (p + c) is necessarily in bounds. Imagine that (p + o) is one past the end of the object, and c is -1. Then p + c might point before the beginning of the object.

We should not give up too easily, however, because is p is some known object we might be able to easily determine whether (p + c) is still inbounds. One way to do this would be to call:

  V->stripAndAccumulateInBoundsConstantOffsets

on the base pointer and then see if we determine the size of the object. You can call getObjectSize(...) to attempt to figure this out (include/llvm/Analysis/MemoryBuiltins.h).


================
Comment at: lib/Transforms/Scalar/LICM.cpp:415
@@ +414,3 @@
+
+      if (canSwapOperandAndHoistGEPs(&I, INext, CurLoop, NumOfGepBaseUses)) {
+        swapGEPOperands(&I, INext);
----------------
This seems a bit odd. We should not be looking only at the very next instruction. At the very least, check for users in the same block.


Repository:
  rL LLVM

http://reviews.llvm.org/D11051







More information about the llvm-commits mailing list