[NaryReassociate] speeds up candidate searching
authorJingyue Wu <jingyue@google.com>
Thu, 16 Apr 2015 18:42:31 +0000 (18:42 +0000)
committerJingyue Wu <jingyue@google.com>
Thu, 16 Apr 2015 18:42:31 +0000 (18:42 +0000)
commitfeecc904c42b0a54db2f6e1196312a7297590374
tree184c08ed6f4f6645d0dc3c9a710449c24d4f6d15
parente60729f73f4c6b0d2c709863dca6787f783e551c
[NaryReassociate] speeds up candidate searching

Summary:
This fixes a left-over efficiency issue in D8950.

As Andrew and Daniel suggested, we can store the candidates in a stack
and pop the top element when it does not dominate the current
instruction. This reduces the worst-case time complexity to O(n).

Test Plan: a new test in nary-add.ll that exercises this optimization.

Reviewers: broune, dberlin, meheff, atrick

Reviewed By: atrick

Subscribers: llvm-commits, sanjoy

Differential Revision: http://reviews.llvm.org/D9055

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235129 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/NaryReassociate.cpp
test/Transforms/NaryReassociate/nary-add.ll