]> granicus.if.org Git - llvm/commitdiff
[SLSR] Call getPointerSizeInBits with the correct address space.
authorJingyue Wu <jingyue@google.com>
Mon, 11 Jul 2016 18:13:28 +0000 (18:13 +0000)
committerJingyue Wu <jingyue@google.com>
Mon, 11 Jul 2016 18:13:28 +0000 (18:13 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275083 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
test/Transforms/StraightLineStrengthReduce/slsr-gep.ll

index 77f0a78b928d4777afb84b163b4243c237b05d9e..292d0400a516b7e1b9c325d9e5de603e7b492cc4 100644 (file)
@@ -505,7 +505,7 @@ void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForGEP(
     Value *ArrayIdx = GEP->getOperand(I);
     uint64_t ElementSize = DL->getTypeAllocSize(*GTI);
     if (ArrayIdx->getType()->getIntegerBitWidth() <=
-        DL->getPointerSizeInBits()) {
+        DL->getPointerSizeInBits(GEP->getAddressSpace())) {
       // Skip factoring if ArrayIdx is wider than the pointer size, because
       // ArrayIdx is implicitly truncated to the pointer size.
       factorArrayIndex(ArrayIdx, BaseExpr, ElementSize, GEP);
@@ -516,7 +516,7 @@ void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForGEP(
     Value *TruncatedArrayIdx = nullptr;
     if (match(ArrayIdx, m_SExt(m_Value(TruncatedArrayIdx))) &&
         TruncatedArrayIdx->getType()->getIntegerBitWidth() <=
-            DL->getPointerSizeInBits()) {
+            DL->getPointerSizeInBits(GEP->getAddressSpace())) {
       // Skip factoring if TruncatedArrayIdx is wider than the pointer size,
       // because TruncatedArrayIdx is implicitly truncated to the pointer size.
       factorArrayIndex(TruncatedArrayIdx, BaseExpr, ElementSize, GEP);
index 573c33cb858bc295957b3d3fd3bf296d65619be0..b9bb4faf1b41486f10460f2569d41803939ce362 100644 (file)
@@ -1,6 +1,6 @@
 ; RUN: opt < %s -slsr -gvn -S | FileCheck %s
 
-target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
+target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64-p:64:64:64-p1:32:32:32"
 
 ; foo(input[0]);
 ; foo(input[s]);
@@ -149,8 +149,8 @@ define void @slsr_out_of_bounds_gep(i32* %input, i32 %s) {
   ret void
 }
 
-define void @slsr_gep_128bit(i32* %input, i128 %s) {
-; CHECK-LABEL: @slsr_gep_128bit(
+define void @slsr_gep_128bit_index(i32* %input, i128 %s) {
+; CHECK-LABEL: @slsr_gep_128bit_index(
   ; p0 = &input[0]
   %p0 = getelementptr inbounds i32, i32* %input, i128 0
   call void @foo(i32* %p0)
@@ -170,5 +170,22 @@ define void @slsr_gep_128bit(i32* %input, i128 %s) {
   ret void
 }
 
+define void @slsr_gep_32bit_pointer(i32 addrspace(1)* %input, i64 %s) {
+; CHECK-LABEL: @slsr_gep_32bit_pointer(
+  ; p1 = &input[s]
+  %p1 = getelementptr inbounds i32, i32 addrspace(1)* %input, i64 %s
+  call void @baz(i32 addrspace(1)* %p1)
+
+  ; p2 = &input[s * 2]
+  %s2 = mul nsw i64 %s, 2
+  %p2 = getelementptr inbounds i32, i32 addrspace(1)* %input, i64 %s2
+  ; %s2 is wider than the pointer size of addrspace(1), so do not factor it.
+; CHECK: %p2 = getelementptr inbounds i32, i32 addrspace(1)* %input, i64 %s2
+  call void @baz(i32 addrspace(1)* %p2)
+
+  ret void
+}
+
 declare void @foo(i32*)
 declare void @bar(i64*)
+declare void @baz(i32 addrspace(1)*)