1 ; This testcase tests for various features the basicaa test should be able to 2 ; determine, as noted in the comments. 3 4 ; RUN: opt < %s -basicaa -gvn -instcombine -dce -S | FileCheck %s 5 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128" 6 7 @Global = external global { i32 } 8 9 declare void @external(i32*) 10 11 ; Array test: Test that operations on one local array do not invalidate 12 ; operations on another array. Important for scientific codes. 13 ; 14 define i32 @different_array_test(i64 %A, i64 %B) { 15 %Array1 = alloca i32, i32 100 16 %Array2 = alloca i32, i32 200 17 18 call void @external(i32* %Array1) 19 call void @external(i32* %Array2) 20 21 %pointer = getelementptr i32, i32* %Array1, i64 %A 22 %val = load i32, i32* %pointer 23 24 %pointer2 = getelementptr i32, i32* %Array2, i64 %B 25 store i32 7, i32* %pointer2 26 27 %REMOVE = load i32, i32* %pointer ; redundant with above load 28 %retval = sub i32 %REMOVE, %val 29 ret i32 %retval 30 ; CHECK: @different_array_test 31 ; CHECK: ret i32 0 32 } 33 34 ; Constant index test: Constant indexes into the same array should not 35 ; interfere with each other. Again, important for scientific codes. 36 ; 37 define i32 @constant_array_index_test() { 38 %Array = alloca i32, i32 100 39 call void @external(i32* %Array) 40 41 %P1 = getelementptr i32, i32* %Array, i64 7 42 %P2 = getelementptr i32, i32* %Array, i64 6 43 44 %A = load i32, i32* %P1 45 store i32 1, i32* %P2 ; Should not invalidate load 46 %BREMOVE = load i32, i32* %P1 47 %Val = sub i32 %A, %BREMOVE 48 ret i32 %Val 49 ; CHECK: @constant_array_index_test 50 ; CHECK: ret i32 0 51 } 52 53 ; Test that if two pointers are spaced out by a constant getelementptr, that 54 ; they cannot alias. 55 define i32 @gep_distance_test(i32* %A) { 56 %REMOVEu = load i32, i32* %A 57 %B = getelementptr i32, i32* %A, i64 2 ; Cannot alias A 58 store i32 7, i32* %B 59 %REMOVEv = load i32, i32* %A 60 %r = sub i32 %REMOVEu, %REMOVEv 61 ret i32 %r 62 ; CHECK: @gep_distance_test 63 ; CHECK: ret i32 0 64 } 65 66 ; Test that if two pointers are spaced out by a constant offset, that they 67 ; cannot alias, even if there is a variable offset between them... 68 define i32 @gep_distance_test2({i32,i32}* %A, i64 %distance) { 69 %A1 = getelementptr {i32,i32}, {i32,i32}* %A, i64 0, i32 0 70 %REMOVEu = load i32, i32* %A1 71 %B = getelementptr {i32,i32}, {i32,i32}* %A, i64 %distance, i32 1 72 store i32 7, i32* %B ; B cannot alias A, it's at least 4 bytes away 73 %REMOVEv = load i32, i32* %A1 74 %r = sub i32 %REMOVEu, %REMOVEv 75 ret i32 %r 76 ; CHECK: @gep_distance_test2 77 ; CHECK: ret i32 0 78 } 79 80 ; Test that we can do funny pointer things and that distance calc will still 81 ; work. 82 define i32 @gep_distance_test3(i32 * %A) { 83 %X = load i32, i32* %A 84 %B = bitcast i32* %A to i8* 85 %C = getelementptr i8, i8* %B, i64 4 86 store i8 42, i8* %C 87 %Y = load i32, i32* %A 88 %R = sub i32 %X, %Y 89 ret i32 %R 90 ; CHECK: @gep_distance_test3 91 ; CHECK: ret i32 0 92 } 93 94 ; Test that we can disambiguate globals reached through constantexpr geps 95 define i32 @constexpr_test() { 96 %X = alloca i32 97 call void @external(i32* %X) 98 99 %Y = load i32, i32* %X 100 store i32 5, i32* getelementptr ({ i32 }, { i32 }* @Global, i64 0, i32 0) 101 %REMOVE = load i32, i32* %X 102 %retval = sub i32 %Y, %REMOVE 103 ret i32 %retval 104 ; CHECK: @constexpr_test 105 ; CHECK: ret i32 0 106 } 107 108 109 110 ; PR7589 111 ; These two index expressions are different, this cannot be CSE'd. 112 define i16 @zext_sext_confusion(i16* %row2col, i5 %j) nounwind{ 113 entry: 114 %sum5.cast = zext i5 %j to i64 ; <i64> [#uses=1] 115 %P1 = getelementptr i16, i16* %row2col, i64 %sum5.cast 116 %row2col.load.1.2 = load i16, i16* %P1, align 1 ; <i16> [#uses=1] 117 118 %sum13.cast31 = sext i5 %j to i6 ; <i6> [#uses=1] 119 %sum13.cast = zext i6 %sum13.cast31 to i64 ; <i64> [#uses=1] 120 %P2 = getelementptr i16, i16* %row2col, i64 %sum13.cast 121 %row2col.load.1.6 = load i16, i16* %P2, align 1 ; <i16> [#uses=1] 122 123 %.ret = sub i16 %row2col.load.1.6, %row2col.load.1.2 ; <i16> [#uses=1] 124 ret i16 %.ret 125 ; CHECK: @zext_sext_confusion 126 ; CHECK: ret i16 %.ret 127 } 128