2002-09-08 18:08:36 +00:00
|
|
|
; This testcase tests for various features the basicaa test should be able to
|
|
|
|
; determine, as noted in the comments.
|
|
|
|
|
2006-12-02 04:23:10 +00:00
|
|
|
; RUN: llvm-upgrade < %s | llvm-as | opt -basicaa -load-vn -gcse -instcombine -dce | llvm-dis | not grep REMOVE
|
2002-09-08 18:08:36 +00:00
|
|
|
|
2003-06-17 15:16:35 +00:00
|
|
|
%Global = external global { int }
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
2002-09-08 18:08:36 +00:00
|
|
|
|
|
|
|
; Array test: Test that operations on one local array do not invalidate
|
|
|
|
; operations on another array. Important for scientific codes.
|
|
|
|
;
|
2002-10-25 22:29:07 +00:00
|
|
|
int %different_array_test(long %A, long %B) {
|
2002-09-08 18:08:36 +00:00
|
|
|
%Array1 = alloca int, uint 100
|
|
|
|
%Array2 = alloca int, uint 200
|
|
|
|
|
2002-10-25 22:29:07 +00:00
|
|
|
%pointer = getelementptr int* %Array1, long %A
|
2002-09-08 18:08:36 +00:00
|
|
|
%val = load int* %pointer
|
|
|
|
|
2002-10-25 22:29:07 +00:00
|
|
|
%pointer2 = getelementptr int* %Array2, long %B
|
2002-09-08 18:08:36 +00:00
|
|
|
store int 7, int* %pointer2
|
|
|
|
|
|
|
|
%REMOVE = load int* %pointer ; redundant with above load
|
|
|
|
%retval = sub int %REMOVE, %val
|
|
|
|
ret int %retval
|
|
|
|
}
|
|
|
|
|
|
|
|
; Constant index test: Constant indexes into the same array should not
|
|
|
|
; interfere with each other. Again, important for scientific codes.
|
|
|
|
;
|
|
|
|
int %constant_array_index_test() {
|
|
|
|
%Array = alloca int, uint 100
|
2002-10-25 22:29:07 +00:00
|
|
|
%P1 = getelementptr int* %Array, long 7
|
|
|
|
%P2 = getelementptr int* %Array, long 6
|
2002-09-08 18:08:36 +00:00
|
|
|
|
|
|
|
%A = load int* %P1
|
|
|
|
store int 1, int* %P2 ; Should not invalidate load
|
|
|
|
%BREMOVE = load int* %P1
|
|
|
|
%Val = sub int %A, %BREMOVE
|
|
|
|
ret int %Val
|
|
|
|
}
|
|
|
|
|
2003-02-09 19:01:00 +00:00
|
|
|
; Test that if two pointers are spaced out by a constant getelementptr, that
|
|
|
|
; they cannot alias.
|
|
|
|
int %gep_distance_test(int* %A) {
|
|
|
|
%REMOVEu = load int* %A
|
|
|
|
%B = getelementptr int* %A, long 2 ; Cannot alias A
|
|
|
|
store int 7, int* %B
|
|
|
|
%REMOVEv = load int* %A
|
|
|
|
%r = sub int %REMOVEu, %REMOVEv
|
|
|
|
ret int %r
|
|
|
|
}
|
|
|
|
|
2003-02-25 21:43:37 +00:00
|
|
|
; Test that if two pointers are spaced out by a constant offset, that they
|
|
|
|
; cannot alias, even if there is a variable offset between them...
|
|
|
|
int %gep_distance_test2({int,int}* %A, long %distance) {
|
2006-11-23 15:14:52 +00:00
|
|
|
%A = getelementptr {int,int}* %A, long 0, uint 0
|
2003-02-25 21:43:37 +00:00
|
|
|
%REMOVEu = load int* %A
|
2006-11-23 15:14:52 +00:00
|
|
|
%B = getelementptr {int,int}* %A, long %distance, uint 1
|
2003-02-25 21:43:37 +00:00
|
|
|
store int 7, int* %B ; B cannot alias A, it's at least 4 bytes away
|
|
|
|
%REMOVEv = load int* %A
|
|
|
|
%r = sub int %REMOVEu, %REMOVEv
|
|
|
|
ret int %r
|
|
|
|
}
|
2003-02-26 21:39:52 +00:00
|
|
|
|
2003-02-26 22:01:58 +00:00
|
|
|
; Test that we can do funny pointer things and that distance calc will still
|
|
|
|
; work.
|
|
|
|
int %gep_distance_test3(int * %A) {
|
2003-02-26 21:39:52 +00:00
|
|
|
%X = load int* %A
|
|
|
|
%B = cast int* %A to sbyte*
|
|
|
|
%C = getelementptr sbyte* %B, long 4
|
|
|
|
%Y = load sbyte* %C
|
|
|
|
ret int 8
|
|
|
|
}
|
2003-06-17 15:16:35 +00:00
|
|
|
|
|
|
|
; Test that we can disambiguate globals reached through constantexpr geps
|
|
|
|
int %constexpr_test() {
|
|
|
|
%X = alloca int
|
|
|
|
%Y = load int* %X
|
2006-11-23 15:14:52 +00:00
|
|
|
store int 5, int* getelementptr ({ int }* %Global, long 0, uint 0)
|
2003-06-17 15:16:35 +00:00
|
|
|
%REMOVE = load int* %X
|
|
|
|
%retval = sub int %Y, %REMOVE
|
|
|
|
ret int %retval
|
|
|
|
}
|