Do not fold loads into instructions if it is used more than once. In particular
authorChris Lattner <sabre@nondot.org>
Thu, 17 Jun 2004 22:15:25 +0000 (22:15 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 17 Jun 2004 22:15:25 +0000 (22:15 +0000)
we do not want to fold the load in cases like this:

  X = load
    = add A, X
    = add B, X

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

lib/Target/X86/InstSelectSimple.cpp
lib/Target/X86/X86ISelSimple.cpp

index 0c8b0a456677a6e462129c8de3b892e4b6c6e2d6..598a979471a3815f020b908d0c0df7a32cd1420a 100644 (file)
@@ -1964,11 +1964,12 @@ void ISel::visitSimpleBinary(BinaryOperator &B, unsigned OperatorClass) {
 
   // Special case: op Reg, load [mem]
   if (isa<LoadInst>(Op0) && !isa<LoadInst>(Op1) && Class != cLong &&
+      Op0->hasOneUse() && 
       isSafeToFoldLoadIntoInstruction(*cast<LoadInst>(Op0), B))
     if (!B.swapOperands())
       std::swap(Op0, Op1);  // Make sure any loads are in the RHS.
 
-  if (isa<LoadInst>(Op1) && Class != cLong &&
+  if (isa<LoadInst>(Op1) && Class != cLong && Op1->hasOneUse() &&
       isSafeToFoldLoadIntoInstruction(*cast<LoadInst>(Op1), B)) {
 
     unsigned Opcode;
index 0c8b0a456677a6e462129c8de3b892e4b6c6e2d6..598a979471a3815f020b908d0c0df7a32cd1420a 100644 (file)
@@ -1964,11 +1964,12 @@ void ISel::visitSimpleBinary(BinaryOperator &B, unsigned OperatorClass) {
 
   // Special case: op Reg, load [mem]
   if (isa<LoadInst>(Op0) && !isa<LoadInst>(Op1) && Class != cLong &&
+      Op0->hasOneUse() && 
       isSafeToFoldLoadIntoInstruction(*cast<LoadInst>(Op0), B))
     if (!B.swapOperands())
       std::swap(Op0, Op1);  // Make sure any loads are in the RHS.
 
-  if (isa<LoadInst>(Op1) && Class != cLong &&
+  if (isa<LoadInst>(Op1) && Class != cLong && Op1->hasOneUse() &&
       isSafeToFoldLoadIntoInstruction(*cast<LoadInst>(Op1), B)) {
 
     unsigned Opcode;