diff options
| author | Owen Anderson <resistor@mac.com> | 2014-10-05 23:41:26 +0000 |
|---|---|---|
| committer | Owen Anderson <resistor@mac.com> | 2014-10-05 23:41:26 +0000 |
| commit | 8373d338f6f0f5462cf10704e904b0c359dddd3e (patch) | |
| tree | ca0c4faaa07a5bb9c8b44987fdb684bfa2cb77af /llvm/lib/Transforms/Scalar/Reassociate.cpp | |
| parent | 2f03c8a38d57010a924f7367b3c3b57076ab242a (diff) | |
| download | bcm5719-llvm-8373d338f6f0f5462cf10704e904b0c359dddd3e.tar.gz bcm5719-llvm-8373d338f6f0f5462cf10704e904b0c359dddd3e.zip | |
Give the Reassociate pass a bit more flexibility and autonomy when optimizing expressions.
Particularly, it addresses cases where Reassociate breaks Subtracts but then fails to optimize combinations like I1 + -I2 where I1 and I2 have the same rank and are identical.
Patch by Dmitri Shtilman.
llvm-svn: 219092
Diffstat (limited to 'llvm/lib/Transforms/Scalar/Reassociate.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/Reassociate.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index d0cd48a3a26..b8fb25d0b9a 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp @@ -1034,13 +1034,23 @@ static unsigned FindInOperandList(SmallVectorImpl<ValueEntry> &Ops, unsigned i, Value *X) { unsigned XRank = Ops[i].Rank; unsigned e = Ops.size(); - for (unsigned j = i+1; j != e && Ops[j].Rank == XRank; ++j) + for (unsigned j = i+1; j != e && Ops[j].Rank == XRank; ++j) { if (Ops[j].Op == X) return j; + if (Instruction *I1 = dyn_cast<Instruction>(Ops[j].Op)) + if (Instruction *I2 = dyn_cast<Instruction>(X)) + if (I1->isIdenticalTo(I2)) + return j; + } // Scan backwards. - for (unsigned j = i-1; j != ~0U && Ops[j].Rank == XRank; --j) + for (unsigned j = i-1; j != ~0U && Ops[j].Rank == XRank; --j) { if (Ops[j].Op == X) return j; + if (Instruction *I1 = dyn_cast<Instruction>(Ops[j].Op)) + if (Instruction *I2 = dyn_cast<Instruction>(X)) + if (I1->isIdenticalTo(I2)) + return j; + } return i; } |

