From 1c9ca7d101354e5478ef064e52c8ca174bd80aa0 Mon Sep 17 00:00:00 2001 From: Diego Trevino Ferrer Date: Wed, 7 Aug 2019 00:42:50 +0000 Subject: [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: 368115 --- llvm/test/Reduce/Inputs/remove-global-vars.sh | 9 +++++++ llvm/test/Reduce/remove-global-vars.ll | 38 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 llvm/test/Reduce/Inputs/remove-global-vars.sh create mode 100644 llvm/test/Reduce/remove-global-vars.ll (limited to 'llvm/test/Reduce') diff --git a/llvm/test/Reduce/Inputs/remove-global-vars.sh b/llvm/test/Reduce/Inputs/remove-global-vars.sh new file mode 100755 index 00000000000..cb656878cd9 --- /dev/null +++ b/llvm/test/Reduce/Inputs/remove-global-vars.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +matches=$(cat $1 | grep "@interesting = global" | wc -l) + +if [[ $matches > 0 ]]; then + exit 0 +else + exit 1 +fi diff --git a/llvm/test/Reduce/remove-global-vars.ll b/llvm/test/Reduce/remove-global-vars.ll new file mode 100644 index 00000000000..7acd35fd612 --- /dev/null +++ b/llvm/test/Reduce/remove-global-vars.ll @@ -0,0 +1,38 @@ +; Test that llvm-reduce can remove uninteresting Global Variables as well as +; their direct uses. +; +; RUN: llvm-reduce --test %p/Inputs/remove-global-vars.sh %s +; RUN: cat reduced.ll | FileCheck %s +; REQUIRES: plugins, shell + +@uninteresting1 = global i32 0, align 4 +; CHECK: @interesting = global +@interesting = global i32 5, align 4 +; CHECK-NOT: global +@uninteresting2 = global i32 25, align 4 +@uninteresting3 = global i32 50, align 4 + +define i32 @main() { +entry: + %retval = alloca i32, align 4 + store i32 0, i32* %retval, align 4 + ; CHECK-NOT: load i32, i32* @uninteresting2, align 4 + %0 = load i32, i32* @uninteresting2, align 4 + store i32 %0, i32* @interesting, align 4 + ; CHECK-NOT: load i32, i32* @uninteresting3, align 4 + %1 = load i32, i32* @uninteresting3, align 4 + %dec = add nsw i32 %1, -1 + ; CHECK-NOT: store i32 %dec, i32* @uninteresting3, align 4 + store i32 %dec, i32* @uninteresting3, align 4 + ; CHECK: load i32, i32* @interesting, align 4 + %2 = load i32, i32* @interesting, align 4 + ; CHECK-NOT: load i32, i32* @uninteresting2, align 4 + %3 = load i32, i32* @uninteresting2, align 4 + %add = add nsw i32 %2, %3 + ; CHECK-NOT: store i32 %add, i32* @uninteresting1, align 4 + store i32 %add, i32* @uninteresting1, align 4 + store i32 10, i32* @interesting, align 4 + ; CHECK: load i32, i32* @interesting, align 4 + %4 = load i32, i32* @interesting, align 4 + ret i32 0 +} -- cgit v1.2.3