diff options
-rw-r--r-- | lib/Analysis/BasicAliasAnalysis.cpp | 5 | ||||
-rw-r--r-- | test/Analysis/BasicAA/gep-alias.ll | 29 | ||||
-rw-r--r-- | test/Analysis/BasicAA/global-size.ll | 14 |
3 files changed, 44 insertions, 4 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index bf92969..b2c2011 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -326,6 +326,7 @@ DecomposeGEPExpression(const Value *V, int64_t &BaseOffs, continue; } + unsigned AS = GEPOp->getPointerAddressSpace(); // Walk the indices of the GEP, accumulating them into BaseOff/VarIndices. gep_type_iterator GTI = gep_type_begin(GEPOp); for (User::const_op_iterator I = GEPOp->op_begin()+1, @@ -354,7 +355,7 @@ DecomposeGEPExpression(const Value *V, int64_t &BaseOffs, // If the integer type is smaller than the pointer size, it is implicitly // sign extended to pointer size. unsigned Width = Index->getType()->getIntegerBitWidth(); - if (TD->getPointerSizeInBits() > Width) + if (TD->getPointerSizeInBits(AS) > Width) Extension = EK_SignExt; // Use GetLinearExpression to decompose the index into a C1*V+C2 form. @@ -382,7 +383,7 @@ DecomposeGEPExpression(const Value *V, int64_t &BaseOffs, // Make sure that we have a scale that makes sense for this target's // pointer size. - if (unsigned ShiftBits = 64-TD->getPointerSizeInBits()) { + if (unsigned ShiftBits = 64 - TD->getPointerSizeInBits(AS)) { Scale <<= ShiftBits; Scale = (int64_t)Scale >> ShiftBits; } diff --git a/test/Analysis/BasicAA/gep-alias.ll b/test/Analysis/BasicAA/gep-alias.ll index d7f783d4..2c0d467 100644 --- a/test/Analysis/BasicAA/gep-alias.ll +++ b/test/Analysis/BasicAA/gep-alias.ll @@ -1,6 +1,6 @@ ; RUN: opt < %s -basicaa -gvn -instcombine -S 2>&1 | FileCheck %s -target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" +target datalayout = "e-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" ; Make sure that basicaa thinks R and r are must aliases. define i32 @test1(i8 * %P) { @@ -86,6 +86,33 @@ define i32 @test5(i32* %p, i64 %i) { ; CHECK: ret i32 0 } +define i32 @test5_as1_smaller_size(i32 addrspace(1)* %p, i8 %i) { + %pi = getelementptr i32 addrspace(1)* %p, i8 %i + %i.next = add i8 %i, 1 + %pi.next = getelementptr i32 addrspace(1)* %p, i8 %i.next + %x = load i32 addrspace(1)* %pi + store i32 42, i32 addrspace(1)* %pi.next + %y = load i32 addrspace(1)* %pi + %z = sub i32 %x, %y + ret i32 %z +; CHECK-LABEL: @test5_as1_smaller_size( +; CHECK: sext +; CHECK: ret i32 0 +} + +define i32 @test5_as1_same_size(i32 addrspace(1)* %p, i16 %i) { + %pi = getelementptr i32 addrspace(1)* %p, i16 %i + %i.next = add i16 %i, 1 + %pi.next = getelementptr i32 addrspace(1)* %p, i16 %i.next + %x = load i32 addrspace(1)* %pi + store i32 42, i32 addrspace(1)* %pi.next + %y = load i32 addrspace(1)* %pi + %z = sub i32 %x, %y + ret i32 %z +; CHECK-LABEL: @test5_as1_same_size( +; CHECK: ret i32 0 +} + ; P[i] != p[(i*4)|1] define i32 @test6(i32* %p, i64 %i1) { %i = shl i64 %i1, 2 diff --git a/test/Analysis/BasicAA/global-size.ll b/test/Analysis/BasicAA/global-size.ll index cc6cc4b..f081cb1 100644 --- a/test/Analysis/BasicAA/global-size.ll +++ b/test/Analysis/BasicAA/global-size.ll @@ -2,7 +2,7 @@ ; the global. ; RUN: opt < %s -basicaa -gvn -S | FileCheck %s -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" +target datalayout = "E-p:64:64:64-p1:16:16:16-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" @B = global i16 8 @@ -16,6 +16,18 @@ define i16 @test1(i32* %P) { ; CHECK: ret i16 0 } +@B_as1 = addrspace(1) global i16 8 + +define i16 @test1_as1(i32 addrspace(1)* %P) { +; CHECK-LABEL: @test1_as1( +; CHECK: ret i16 0 + %X = load i16 addrspace(1)* @B_as1 + store i32 7, i32 addrspace(1)* %P + %Y = load i16 addrspace(1)* @B_as1 + %Z = sub i16 %Y, %X + ret i16 %Z +} + ; Cannot know anything about the size of this global. ; rdar://8813415 @window = external global [0 x i8] |