Don't attempt load PRE when there is no real redundancy (i.e., the load is in
authorBob Wilson <bob.wilson@apple.com>
Tue, 2 Mar 2010 00:09:29 +0000 (00:09 +0000)
committerBob Wilson <bob.wilson@apple.com>
Tue, 2 Mar 2010 00:09:29 +0000 (00:09 +0000)
a loop and is itself the only dependency).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97526 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/GVN.cpp

index a4c071602491a5412b5dd42ee1f384c15aeb19a6..fcb802a72ae0849a6e4425feb7ed8cd07b69eeca 100644 (file)
@@ -1542,11 +1542,13 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
   // at least one of the values is LI.  Since this means that we won't be able
   // to eliminate LI even if we insert uses in the other predecessors, we will
   // end up increasing code size.  Reject this by scanning for LI.
-  if (!EnableFullLoadPRE) {
-    for (unsigned i = 0, e = ValuesPerBlock.size(); i != e; ++i)
-      if (ValuesPerBlock[i].isSimpleValue() &&
-          ValuesPerBlock[i].getSimpleValue() == LI)
+  for (unsigned i = 0, e = ValuesPerBlock.size(); i != e; ++i) {
+    if (ValuesPerBlock[i].isSimpleValue() &&
+        ValuesPerBlock[i].getSimpleValue() == LI) {
+      // Skip cases where LI is the only definition, even for EnableFullLoadPRE.
+      if (!EnableFullLoadPRE || e == 1)
         return false;
+    }
   }
 
   // FIXME: It is extremely unclear what this loop is doing, other than