diff options
| author | Diego Trevino Ferrer <diegof30@gmail.com> | 2019-08-14 21:01:19 +0000 |
|---|---|---|
| committer | Diego Trevino Ferrer <diegof30@gmail.com> | 2019-08-14 21:01:19 +0000 |
| commit | d1ffcd07456bc8b64056eeec223e87b48fca93b9 (patch) | |
| tree | 283ee54a28d6a02fc3bfa6d022230c3e614623a8 /llvm/test/Reduce | |
| parent | c17705b7fb192fb03d9f2a540bc918f19f965225 (diff) | |
| download | bcm5719-llvm-d1ffcd07456bc8b64056eeec223e87b48fca93b9.tar.gz bcm5719-llvm-d1ffcd07456bc8b64056eeec223e87b48fca93b9.zip | |
[Bugpoint redesign] Added Pass to Remove Global Variables
Summary:
This pass tries to remove Global Variables, as well as their derived uses. For example if a variable `@x` is used by `%call1` and `%call2`, both these uses and the definition of `@x` are deleted. Moreover if `%call1` or `%call2` are used elsewhere those uses are also deleted, and so on recursively.
I'm still uncertain if this pass should remove derived uses, I'm open to suggestions.
Subscribers: mgorny, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D64176
llvm-svn: 368918
Diffstat (limited to 'llvm/test/Reduce')
| -rwxr-xr-x | llvm/test/Reduce/Inputs/remove-global-vars.py | 10 | ||||
| -rw-r--r-- | llvm/test/Reduce/remove-funcs.ll | 2 | ||||
| -rw-r--r-- | llvm/test/Reduce/remove-global-vars.ll | 30 |
3 files changed, 41 insertions, 1 deletions
diff --git a/llvm/test/Reduce/Inputs/remove-global-vars.py b/llvm/test/Reduce/Inputs/remove-global-vars.py new file mode 100755 index 00000000000..81fbea937dd --- /dev/null +++ b/llvm/test/Reduce/Inputs/remove-global-vars.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +import sys + +input = open(sys.argv[1], "r") +for line in input: + if "@interesting = global" in line: + sys.exit(0) + +sys.exit(1) # IR isn't interesting diff --git a/llvm/test/Reduce/remove-funcs.ll b/llvm/test/Reduce/remove-funcs.ll index 7d6fba86cc3..a0ce24a7f07 100644 --- a/llvm/test/Reduce/remove-funcs.ll +++ b/llvm/test/Reduce/remove-funcs.ll @@ -3,7 +3,7 @@ ; ; RUN: llvm-reduce --test %p/Inputs/remove-funcs.py %s ; RUN: cat reduced.ll | FileCheck %s -; REQUIRES: plugins, shell +; REQUIRES: plugins ; CHECK-NOT: uninteresting1() define i32 @uninteresting1() { diff --git a/llvm/test/Reduce/remove-global-vars.ll b/llvm/test/Reduce/remove-global-vars.ll new file mode 100644 index 00000000000..1241cd2c310 --- /dev/null +++ b/llvm/test/Reduce/remove-global-vars.ll @@ -0,0 +1,30 @@ +; Test that llvm-reduce can remove uninteresting Global Variables as well as +; their direct uses (which in turn are replaced with 'undef'). +; +; RUN: llvm-reduce --test %p/Inputs/remove-global-vars.py %s +; RUN: cat reduced.ll | FileCheck %s +; REQUIRES: plugins + +; CHECK: @interesting = global +@interesting = global i32 0, align 4 +; CHECK-NOT: global +@uninteresting = global i32 1, align 4 + +define i32 @main() { +entry: + ; CHECK-NOT: load i32, i32* @uninteresting, align 4 + %0 = load i32, i32* @uninteresting, align 4 + ; CHECK: store i32 undef, i32* @interesting, align 4 + store i32 %0, i32* @interesting, align 4 + + ; CHECK: load i32, i32* @interesting, align 4 + %1 = load i32, i32* @interesting, align 4 + ; CHECK-NOT: store i32 %1, i32* @uninteresting, align 4 + store i32 %1, i32* @uninteresting, align 4 + + ; CHECK: %inc = add nsw i32 undef, 1 + %inc = add nsw i32 %0, 1 + ; CHECK: store i32 %inc, i32* @interesting, align 4 + store i32 %inc, i32* @interesting, align 4 + ret i32 0 +} |

