[llvm-commits] [llvm] r92354 - in /llvm/trunk: lib/Transforms/Scalar/Reassociate.cpp test/Transforms/Reassociate/basictest.ll

Chris Lattner sabre at nondot.org
Thu Dec 31 00:33:49 PST 2009


Author: lattner
Date: Thu Dec 31 02:33:49 2009
New Revision: 92354

URL: http://llvm.org/viewvc/llvm-project?rev=92354&view=rev
Log:
simple fix for an incorrect factoring which causes a
miscompilation, PR5458.

Modified:
    llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
    llvm/trunk/test/Transforms/Reassociate/basictest.ll

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=92354&r1=92353&r2=92354&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Thu Dec 31 02:33:49 2009
@@ -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);

Modified: llvm/trunk/test/Transforms/Reassociate/basictest.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Reassociate/basictest.ll?rev=92354&r1=92353&r2=92354&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/Reassociate/basictest.ll (original)
+++ llvm/trunk/test/Transforms/Reassociate/basictest.ll Thu Dec 31 02:33:49 2009
@@ -133,3 +133,14 @@
 ; CHECK-NEXT: %C = sub i32 %Z, %A
 ; CHECK-NEXT: ret i32 %C
 }
+
+
+; PR5458
+define i32 @test9(i32 %X) {
+  %Y = mul i32 %X, 47
+  %Z = add i32 %Y, %Y
+  ret i32 %Z
+; CHECK: @test9
+; CHECK-NEXT: %Z = mul i32 %X, 94
+; CHECK-NEXT: ret i32 %Z
+}





More information about the llvm-commits mailing list