Arthur Eubanks | feeed16 | 2020-06-26 14:58:01 -0700 | [diff] [blame] | 1 | ; RUN: opt < %s -basic-aa -aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s |
Quentin Colombet | 5989bc6 | 2015-08-31 22:32:47 +0000 | [diff] [blame] | 2 | target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" |
| 3 | target triple = "thumbv7--linux-gnueabi" |
| 4 | |
| 5 | ; CHECK-LABEL: test_zext_sext_amounts255 |
| 6 | ; CHECK: NoAlias: i8* %a, i8* %b |
| 7 | define void @test_zext_sext_amounts255(i8* %mem) { |
| 8 | %sext.1 = sext i8 255 to i16 |
| 9 | %sext.zext.1 = zext i16 %sext.1 to i64 |
| 10 | %sext.2 = sext i8 255 to i32 |
| 11 | %sext.zext.2 = zext i32 %sext.2 to i64 |
| 12 | %a = getelementptr inbounds i8, i8* %mem, i64 %sext.zext.1 |
| 13 | %b = getelementptr inbounds i8, i8* %mem, i64 %sext.zext.2 |
| 14 | ret void |
| 15 | } |
| 16 | |
| 17 | ; CHECK-LABEL: test_zext_sext_amounts |
Michael Kruse | 47f8560 | 2017-06-21 18:25:37 +0000 | [diff] [blame] | 18 | ; CHECK: MayAlias: i8* %a, i8* %b |
Quentin Colombet | 5989bc6 | 2015-08-31 22:32:47 +0000 | [diff] [blame] | 19 | ; %a and %b only PartialAlias as, although they're both zext(sext(%num)) they'll extend the sign by a different |
| 20 | ; number of bits before zext-ing the remainder. |
| 21 | define void @test_zext_sext_amounts(i8* %mem, i8 %num) { |
| 22 | %sext.1 = sext i8 %num to i16 |
| 23 | %sext.zext.1 = zext i16 %sext.1 to i64 |
| 24 | %sext.2 = sext i8 %num to i32 |
| 25 | %sext.zext.2 = zext i32 %sext.2 to i64 |
| 26 | %a = getelementptr inbounds i8, i8* %mem, i64 %sext.zext.1 |
| 27 | %b = getelementptr inbounds i8, i8* %mem, i64 %sext.zext.2 |
| 28 | ret void |
| 29 | } |
| 30 | |
| 31 | ; CHECK-LABEL: based_on_pr18068 |
| 32 | ; CHECK: NoAlias: i8* %a, i8* %b |
| 33 | ; CHECK: NoAlias: i8* %a, i8* %c |
| 34 | define void @based_on_pr18068(i32 %loaded, i8* %mem) { |
| 35 | %loaded.64 = zext i32 %loaded to i64 |
| 36 | %add1 = add i32 %loaded, -1 ; unsigned wraps unless %loaded == 0 |
| 37 | %add1.64 = zext i32 %add1 to i64 ; is zext(%loaded) always != zext(%loaded - 1)? Yes -> NoAlias |
| 38 | %sub1 = sub i32 %loaded, 1 ; unsigned wraps iff %loaded == 0 |
| 39 | %sub1.64 = zext i32 %sub1 to i64 ; is zext(%loaded) always != zext(%loaded - 1)? Yes -> NoAlias |
| 40 | %a = getelementptr inbounds i8, i8* %mem, i64 %loaded.64 |
| 41 | %b = getelementptr inbounds i8, i8* %mem, i64 %add1.64 |
| 42 | %c = getelementptr inbounds i8, i8* %mem, i64 %sub1.64 |
| 43 | ret void |
| 44 | } |
| 45 | |
| 46 | ; CHECK-LABEL: test_path_dependence |
Michael Kruse | 47f8560 | 2017-06-21 18:25:37 +0000 | [diff] [blame] | 47 | ; CHECK: MayAlias: i8* %a, i8* %b |
Quentin Colombet | 5989bc6 | 2015-08-31 22:32:47 +0000 | [diff] [blame] | 48 | ; CHECK: MustAlias: i8* %a, i8* %c |
Michael Kruse | 47f8560 | 2017-06-21 18:25:37 +0000 | [diff] [blame] | 49 | ; CHECK: MayAlias: i8* %a, i8* %d |
Quentin Colombet | 5989bc6 | 2015-08-31 22:32:47 +0000 | [diff] [blame] | 50 | define void @test_path_dependence(i32 %p, i8* %mem) { |
| 51 | %p.minus1 = add i32 %p, -1 ; this will always unsigned-wrap, unless %p == 0 |
| 52 | %p.minus1.64 = zext i32 %p.minus1 to i64 |
| 53 | %p.64.again = add i64 %p.minus1.64, 1 ; either %p (if we wrapped) or 4294967296 (if we didn't) |
| 54 | |
| 55 | %p.nsw.nuw.minus1 = sub nsw nuw i32 %p, 1 ; as nuw we know %p >= 1, and as nsw %p <= 2147483647 |
| 56 | %p.nsw.nuw.minus1.64 = zext i32 %p.nsw.nuw.minus1 to i64 |
| 57 | %p.nsw.nuw.64.again = add nsw nuw i64 %p.nsw.nuw.minus1.64, 1 ; ...so always exactly %p |
| 58 | |
| 59 | %p.nsw.minus1 = sub nsw i32 %p, 1 ; only nsw, so can only guarantee %p != 0x10000000 |
| 60 | %p.nsw.minus1.64 = zext i32 %p.nsw.minus1 to i64 ; when %p > 0x10000000 (ie <= 0 as a signed number) then the zext will make this a huge positive number |
| 61 | %p.nsw.64.again = add nsw i64 %p.nsw.minus1.64, 1 ; ...and so this is very much != %p |
| 62 | |
| 63 | %p.64 = zext i32 %p to i64 |
| 64 | %a = getelementptr inbounds i8, i8* %mem, i64 %p.64 |
| 65 | %b = getelementptr inbounds i8, i8* %mem, i64 %p.64.again |
| 66 | %c = getelementptr inbounds i8, i8* %mem, i64 %p.nsw.nuw.64.again |
| 67 | %d = getelementptr inbounds i8, i8* %mem, i64 %p.nsw.64.again |
| 68 | ret void |
| 69 | } |
| 70 | |
| 71 | ; CHECK-LABEL: test_zext_sext_255 |
| 72 | ; CHECK: NoAlias: i8* %a, i8* %b |
| 73 | define void @test_zext_sext_255(i8* %mem) { |
| 74 | %zext.255 = zext i8 255 to i16 ; 0x00FF |
| 75 | %sext.255 = sext i8 255 to i16 ; 0xFFFF |
| 76 | %zext.sext.255 = zext i16 %sext.255 to i32 ; 0x0000FFFF |
| 77 | %sext.zext.255 = sext i16 %zext.255 to i32 ; 0x000000FF |
| 78 | %zext.zext.sext.255 = zext i32 %zext.sext.255 to i64 |
| 79 | %zext.sext.zext.255 = zext i32 %sext.zext.255 to i64 |
| 80 | %a = getelementptr inbounds i8, i8* %mem, i64 %zext.zext.sext.255 |
| 81 | %b = getelementptr inbounds i8, i8* %mem, i64 %zext.sext.zext.255 |
| 82 | ret void |
| 83 | } |
| 84 | |
| 85 | ; CHECK-LABEL: test_zext_sext_num |
Michael Kruse | 47f8560 | 2017-06-21 18:25:37 +0000 | [diff] [blame] | 86 | ; CHECK: MayAlias: i8* %a, i8* %b |
Quentin Colombet | 5989bc6 | 2015-08-31 22:32:47 +0000 | [diff] [blame] | 87 | ; %a and %b NoAlias if %num == 255 (see @test_zext_sext_255), but %a and %b NoAlias for other values of %num (e.g. 0) |
| 88 | define void @test_zext_sext_num(i8* %mem, i8 %num) { |
| 89 | %zext.num = zext i8 %num to i16 |
| 90 | %sext.num = sext i8 %num to i16 |
| 91 | %zext.sext.num = zext i16 %sext.num to i32 |
| 92 | %sext.zext.num = sext i16 %zext.num to i32 |
| 93 | %zext.zext.sext.num = zext i32 %zext.sext.num to i64 |
| 94 | %zext.sext.zext.num = zext i32 %sext.zext.num to i64 |
| 95 | %a = getelementptr inbounds i8, i8* %mem, i64 %zext.zext.sext.num |
| 96 | %b = getelementptr inbounds i8, i8* %mem, i64 %zext.sext.zext.num |
| 97 | ret void |
| 98 | } |
| 99 | |
| 100 | ; CHECK-LABEL: uncompressStream |
| 101 | ; CHECK: MustAlias: i8* %a, i8* %b |
| 102 | ; CHECK: NoAlias: i8* %a, i8* %c |
| 103 | define void @uncompressStream(i8* %mem) { |
| 104 | %zext.255 = zext i8 255 to i32 |
| 105 | %sext.255 = sext i8 255 to i32 |
| 106 | %a = getelementptr inbounds i8, i8* %mem, i32 255 |
| 107 | %b = getelementptr inbounds i8, i8* %mem, i32 %zext.255 |
| 108 | %c = getelementptr inbounds i8, i8* %mem, i32 %sext.255 |
| 109 | ret void |
| 110 | } |
| 111 | |
| 112 | ; CHECK-LABEL: constantOffsetHeuristic_i3_i32 |
| 113 | ; CHECK: NoAlias: i32* %a, i32* %b |
| 114 | ; CHECK: NoAlias: i32* %a, i32* %c |
| 115 | ; CHECK: NoAlias: i32* %b, i32* %c |
| 116 | define void @constantOffsetHeuristic_i3_i32(i32* %mem, i3 %val) { |
| 117 | %zext.plus.7 = add nsw i3 %val, 7 |
| 118 | %zext.plus.4 = add nsw i3 %val, 4 |
| 119 | %zext.val = zext i3 %val to i32 |
| 120 | %zext.4 = zext i3 %zext.plus.4 to i32 |
| 121 | %zext.7 = zext i3 %zext.plus.7 to i32 |
| 122 | %a = getelementptr inbounds i32, i32* %mem, i32 %zext.4 |
| 123 | %b = getelementptr inbounds i32, i32* %mem, i32 %zext.7 |
| 124 | %c = getelementptr inbounds i32, i32* %mem, i32 %zext.val |
| 125 | ret void |
| 126 | } |
| 127 | |
| 128 | ; CHECK-LABEL: constantOffsetHeuristic_i8_i32 |
| 129 | ; CHECK: NoAlias: i32* %a, i32* %b |
| 130 | ; CHECK: NoAlias: i32* %a, i32* %c |
| 131 | ; CHECK: NoAlias: i32* %b, i32* %c |
| 132 | define void @constantOffsetHeuristic_i8_i32(i32* %mem, i8 %val) { |
| 133 | %zext.plus.7 = add nsw i8 %val, 7 |
| 134 | %zext.plus.4 = add nsw i8 %val, 4 |
| 135 | %zext.val = zext i8 %val to i32 |
| 136 | %zext.4 = zext i8 %zext.plus.4 to i32 |
| 137 | %zext.7 = zext i8 %zext.plus.7 to i32 |
| 138 | %a = getelementptr inbounds i32, i32* %mem, i32 %zext.4 |
| 139 | %b = getelementptr inbounds i32, i32* %mem, i32 %zext.7 |
| 140 | %c = getelementptr inbounds i32, i32* %mem, i32 %zext.val |
| 141 | ret void |
| 142 | } |
| 143 | |
| 144 | ; CHECK-LABEL: constantOffsetHeuristic_i3_i8 |
Michael Kruse | 47f8560 | 2017-06-21 18:25:37 +0000 | [diff] [blame] | 145 | ; CHECK: MayAlias: i32* %a, i32* %b |
Quentin Colombet | 5989bc6 | 2015-08-31 22:32:47 +0000 | [diff] [blame] | 146 | ; CHECK: NoAlias: i32* %a, i32* %c |
Michael Kruse | 47f8560 | 2017-06-21 18:25:37 +0000 | [diff] [blame] | 147 | ; CHECK: MayAlias: i32* %b, i32* %c |
Quentin Colombet | 5989bc6 | 2015-08-31 22:32:47 +0000 | [diff] [blame] | 148 | define void @constantOffsetHeuristic_i3_i8(i8* %mem, i3 %val) { |
| 149 | %zext.plus.7 = add nsw i3 %val, 7 |
| 150 | %zext.plus.4 = add nsw i3 %val, 4 |
| 151 | %zext.val = zext i3 %val to i32 |
| 152 | %zext.4 = zext i3 %zext.plus.4 to i32 |
| 153 | %zext.7 = zext i3 %zext.plus.7 to i32 |
| 154 | %a.8 = getelementptr inbounds i8, i8* %mem, i32 %zext.4 |
| 155 | %b.8 = getelementptr inbounds i8, i8* %mem, i32 %zext.7 |
| 156 | %c.8 = getelementptr inbounds i8, i8* %mem, i32 %zext.val |
| 157 | %a = bitcast i8* %a.8 to i32* |
| 158 | %b = bitcast i8* %b.8 to i32* |
| 159 | %c = bitcast i8* %c.8 to i32* |
| 160 | ret void |
| 161 | } |
| 162 | |
| 163 | ; CHECK-LABEL: constantOffsetHeuristic_i8_i8 |
Michael Kruse | 47f8560 | 2017-06-21 18:25:37 +0000 | [diff] [blame] | 164 | ; CHECK: MayAlias: i32* %a, i32* %b |
Quentin Colombet | 5989bc6 | 2015-08-31 22:32:47 +0000 | [diff] [blame] | 165 | ; CHECK: NoAlias: i32* %a, i32* %c |
| 166 | ; CHECK: NoAlias: i32* %b, i32* %c |
| 167 | define void @constantOffsetHeuristic_i8_i8(i8* %mem, i8 %val) { |
| 168 | %zext.plus.7 = add nsw i8 %val, 7 |
| 169 | %zext.plus.4 = add nsw i8 %val, 4 |
| 170 | %zext.val = zext i8 %val to i32 |
| 171 | %zext.4 = zext i8 %zext.plus.4 to i32 |
| 172 | %zext.7 = zext i8 %zext.plus.7 to i32 |
| 173 | %a.8 = getelementptr inbounds i8, i8* %mem, i32 %zext.4 |
| 174 | %b.8 = getelementptr inbounds i8, i8* %mem, i32 %zext.7 |
| 175 | %c.8 = getelementptr inbounds i8, i8* %mem, i32 %zext.val |
| 176 | %a = bitcast i8* %a.8 to i32* |
| 177 | %b = bitcast i8* %b.8 to i32* |
| 178 | %c = bitcast i8* %c.8 to i32* |
| 179 | ret void |
| 180 | } |