1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 03:53:04 +02:00
llvm-mirror/test/Transforms/GlobalOpt/GSROA-section.ll
Sergei Larin 7b219abac0 Make sure that any new and optimized objects created during GlobalOPT copy all the attributes from the base object.
Summary:
Make sure that any new and optimized objects created during GlobalOPT copy all the attributes from the base object.

A good example of improper behavior in the current implementation is section information associated with the GlobalObject. If a section was set for it, and GlobalOpt is creating/modifying a new object based on this one (often copying the original name), without this change new object will be placed in a default section, resulting in inappropriate properties of the new variable.
The argument here is that if customer specified a section for a variable, any changes to it that compiler does should not cause it to change that section allocation.
Moreover, any other properties worth representation in copyAttributesFrom() should also be propagated.

Reviewers: jmolloy, joker-eph, joker.eph

Subscribers: slarin, joker.eph, rafael, tobiasvk, llvm-commits

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

llvm-svn: 258556
2016-01-22 21:18:20 +00:00

31 lines
1.1 KiB
LLVM

; This test lets globalopt split the global struct and array into different
; values. The pass needs to preserve section attribute.
; RUN: opt < %s -globalopt -S | FileCheck %s
; Check that the new global values still have their section assignment.
; CHECK: @struct
; CHECK: section ".foo"
; CHECK: @array
; CHECK-NOT: section ".foo"
@struct = internal global { i32, i32 } zeroinitializer, section ".foo"
@array = internal global [ 2 x i32 ] zeroinitializer
define i32 @foo() {
%A = load i32, i32* getelementptr ({ i32, i32 }, { i32, i32 }* @struct, i32 0, i32 0)
%B = load i32, i32* getelementptr ([ 2 x i32 ], [ 2 x i32 ]* @array, i32 0, i32 0)
; Use the loaded values, so they won't get removed completely
%R = add i32 %A, %B
ret i32 %R
}
; We put stores in a different function, so that the global variables won't get
; optimized away completely.
define void @bar(i32 %R) {
store i32 %R, i32* getelementptr ([ 2 x i32 ], [ 2 x i32 ]* @array, i32 0, i32 0)
store i32 %R, i32* getelementptr ({ i32, i32 }, { i32, i32 }* @struct, i32 0, i32 0)
ret void
}