[llvm] r276368 - GVN-hoist: move check before mutating the IR

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 21 17:07:01 PDT 2016


Author: spop
Date: Thu Jul 21 19:07:01 2016
New Revision: 276368

URL: http://llvm.org/viewvc/llvm-project?rev=276368&view=rev
Log:
GVN-hoist: move check before mutating the IR

Modified:
    llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp?rev=276368&r1=276367&r2=276368&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVNHoist.cpp Thu Jul 21 19:07:01 2016
@@ -585,9 +585,14 @@ public:
       Gep = dyn_cast<GetElementPtrInst>(St->getPointerOperand());
       Val = dyn_cast<Instruction>(St->getValueOperand());
       // Check that the stored value is available.
-      if (Val && !isa<GetElementPtrInst>(Val) &&
-          !DT->dominates(Val->getParent(), HoistPt))
-        return false;
+      if (Val) {
+        if (isa<GetElementPtrInst>(Val)) {
+          // Check whether we can compute the GEP at HoistPt.
+          if (!allOperandsAvailable(Val, HoistPt))
+            return false;
+        } else if (!DT->dominates(Val->getParent(), HoistPt))
+          return false;
+      }
     }
 
     // Check whether we can compute the Gep at HoistPt.
@@ -613,9 +618,6 @@ public:
 
     // Also copy Val when it is a GEP.
     if (Val && isa<GetElementPtrInst>(Val)) {
-      // Check whether we can compute the GEP at HoistPt.
-      if (!allOperandsAvailable(Val, HoistPt))
-        return false;
       Instruction *ClonedVal = Val->clone();
       ClonedVal->insertBefore(HoistPt->getTerminator());
       // Conservatively discard any optimization hints, they may differ on the




More information about the llvm-commits mailing list