[PATCH] Hoist load based on alias analysis

Elena Demikhovsky elena.demikhovsky at intel.com
Tue Oct 28 00:37:43 PDT 2014


> Does the new implementation catch any cases the old one didn't? There is extra cost by walking the range of instruction twice, and perhaps a small change would have the same effect.
[Demikhovsky, Elena] Exactly, not every store is a barrier for load hoisting. I check this with AliasAnalysis. I attached a test case where it works.

================
Comment at: lib/Transforms/Scalar/MergedLoadStoreMotion.cpp:265
@@ +264,3 @@
+    BasicBlock *BB0 = Load0->getParent();
+    if (Load0->IsIndenticalToWhenDefefined(Load1) &&
+        !isLoadHoistBarrierInRange(BB1->front(), *Load1, Load1) &&
----------------
Gerolf wrote:
> Typo. Did you mean IsIdenticalToDefined()? Or IsIdendicalLoad()?
IsIdenticalToDefined is a standard function to compare 2 instructions.

================
Comment at: lib/Transforms/Scalar/MergedLoadStoreMotion.cpp:267
@@ +266,3 @@
+        !isLoadHoistBarrierInRange(BB1->front(), *Load1, Load1) &&
+        !isLoadHoistBarrierInRange(BB0->front(), *Load0, Load0)) {
+      return Load1;
----------------
Gerolf wrote:
> Are you checking the range for load0 twice? See overall comment.
No. I check only once for each load. I can't say that instruction is a barrier before I see the load itself. Because I go back from bb start to the current instruction, I do it after I see two identical loads.

================
Comment at: lib/Transforms/Scalar/MergedLoadStoreMotion.cpp:371
@@ -393,1 +370,3 @@
+    LoadInst *L0 = dyn_cast<LoadInst>(I);
+    if (!L0 || !L0->isSimple() || L0->isUsedOutsideOfBlock(Succ0))
       continue;
----------------
Gerolf wrote:
> The optimization should work when one load is used outside the block. The optimization can work when both loads are used outside but we have to deal with the PHI nodes accordingly. 
I did not change the current behavior in this case, but I plan to work more on these optimizations. Conditional load/store are barriers for vectorizer.

http://reviews.llvm.org/D5991






More information about the llvm-commits mailing list