Simplify n-ary adds by reassociation
authorJingyue Wu <jingyue@google.com>
Tue, 14 Apr 2015 04:59:22 +0000 (04:59 +0000)
committerJingyue Wu <jingyue@google.com>
Tue, 14 Apr 2015 04:59:22 +0000 (04:59 +0000)
commit9cecacd16af2ec8a5c01f751850cf212b037d779
tree8197cb085427b6331668fc628cdd1ab35c4c1e76
parent35adce33f1f45caf7f77dc2cc75ff893e9826a43
Simplify n-ary adds by reassociation

Summary:
This transformation reassociates a n-ary add so that the add can partially reuse
existing instructions. For example, this pass can simplify

  void foo(int a, int b) {
    bar(a + b);
    bar((a + 2) + b);
  }

to

  void foo(int a, int b) {
    int t = a + b;
    bar(t);
    bar(t + 2);
  }

saving one add instruction.

Fixes PR22357 (https://llvm.org/bugs/show_bug.cgi?id=22357).

Test Plan: nary-add.ll

Reviewers: broune, dberlin, hfinkel, meheff, sanjoy, atrick

Reviewed By: sanjoy, atrick

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234855 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/InitializePasses.h
include/llvm/LinkAllPasses.h
include/llvm/Transforms/Scalar.h
lib/Transforms/Scalar/CMakeLists.txt
lib/Transforms/Scalar/NaryReassociate.cpp [new file with mode: 0644]
lib/Transforms/Scalar/Scalar.cpp
test/Transforms/NaryReassociate/nary-add.ll [new file with mode: 0644]