simple fix for an incorrect factoring which causes a
miscompilation, PR5458.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92354 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index a2d6f08..195bd69 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/lib/Transforms/Scalar/Reassociate.cpp
@@ -714,6 +714,10 @@
     // To efficiently find this, we count the number of times a factor occurs
     // for any ADD operands that are MULs.
     DenseMap<Value*, unsigned> FactorOccurrences;
+      
+    // Keep track of each multiply we see, to avoid triggering on (X*4)+(X*4)
+    // where they are actually the same multiply.
+    SmallPtrSet<BinaryOperator*, 4> Multiplies;
     unsigned MaxOcc = 0;
     Value *MaxOccVal = 0;
     for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
@@ -721,6 +725,9 @@
       if (BOp == 0 || BOp->getOpcode() != Instruction::Mul || !BOp->use_empty())
         continue;
       
+      // If we've already seen this multiply, don't revisit it.
+      if (!Multiplies.insert(BOp)) continue;
+      
       // Compute all of the factors of this added value.
       SmallVector<Value*, 8> Factors;
       FindSingleUseMultiplyFactors(BOp, Factors);