diff options
author | Chris Lattner <sabre@nondot.org> | 2009-12-31 08:33:49 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-12-31 08:33:49 +0000 |
commit | 13a754ce92ece15cf6b90d9fbc37a5c8a1cca06a (patch) | |
tree | 2bf5824e42c2e3aa1d091246d10dd77ff7400570 | |
parent | 7f4ae5c84cfa0ab5454e3303427f1ee424c0ebcd (diff) |
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
-rw-r--r-- | lib/Transforms/Scalar/Reassociate.cpp | 7 | ||||
-rw-r--r-- | test/Transforms/Reassociate/basictest.ll | 11 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index a2d6f08297..195bd69a4c 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -714,6 +714,10 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I, // 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 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I, 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); diff --git a/test/Transforms/Reassociate/basictest.ll b/test/Transforms/Reassociate/basictest.ll index c7d54af1e4..d96625419d 100644 --- a/test/Transforms/Reassociate/basictest.ll +++ b/test/Transforms/Reassociate/basictest.ll @@ -133,3 +133,14 @@ define i32 @test8(i32 %X, i32 %Y, i32 %Z) { ; 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 +} |