llvm.org GIT mirror llvm / 8963071
BasicAA: We need to check both access sizes when comparing a gep and an underlying object of unknown size. Fixes PR18460. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199351 91177308-0d34-0410-b5e6-96231b3b80d8 Arnold Schwaighofer 6 years ago
2 changed file(s) with 42 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
10081008 return NoAlias;
10091009 }
10101010 } else {
1011 if (V1Size != UnknownSize) {
1011 // We have the situation where:
1012 // + +
1013 // | BaseOffset |
1014 // ---------------->|
1015 // |-->V1Size |-------> V2Size
1016 // GEP1 V2
1017 // We need to know that V2Size is not unknown, otherwise we might have
1018 // stripped a gep with negative index ('gep , -1, ...).
1019 if (V1Size != UnknownSize && V2Size != UnknownSize) {
10121020 if (-(uint64_t)GEP1BaseOffset < V1Size)
10131021 return PartialAlias;
10141022 return NoAlias;
0 ; RUN: opt -S -basicaa -dse < %s | FileCheck %s
1
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
4
5 ; We incorrectly returned noalias in the example below for "ptr.64" and
6 ; "either_ptr.64".
7 ; PR18460
8
9 %nested = type { %nested.i64 }
10 %nested.i64 = type { i64 }
11
12 define i64 @testcase(%nested * noalias %p1, %nested * noalias %p2,
13 i32 %a, i32 %b) {
14 %ptr = getelementptr inbounds %nested* %p1, i64 -1, i32 0
15 %ptr.64 = getelementptr inbounds %nested.i64* %ptr, i64 0, i32 0
16 %ptr2= getelementptr inbounds %nested* %p2, i64 0, i32 0
17 %cmp = icmp ult i32 %a, %b
18 %either_ptr = select i1 %cmp, %nested.i64* %ptr2, %nested.i64* %ptr
19 %either_ptr.64 = getelementptr inbounds %nested.i64* %either_ptr, i64 0, i32 0
20
21 ; Because either_ptr.64 and ptr.64 can alias (we used to return noalias)
22 ; elimination of the first store is not valid.
23
24 ; CHECK: store i64 2
25 ; CHECK: load
26 ; CHECK; store i64 1
27
28 store i64 2, i64* %ptr.64, align 8
29 %r = load i64* %either_ptr.64, align 8
30 store i64 1, i64* %ptr.64, align 8
31 ret i64 %r
32 }