From: Jingyue Wu Date: Mon, 11 Jul 2016 18:13:28 +0000 (+0000) Subject: [SLSR] Call getPointerSizeInBits with the correct address space. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef6651a6f9eb502816fa7c894c3f124b763fbd19;p=llvm [SLSR] Call getPointerSizeInBits with the correct address space. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275083 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp b/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp index 77f0a78b928..292d0400a51 100644 --- a/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp +++ b/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp @@ -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); diff --git a/test/Transforms/StraightLineStrengthReduce/slsr-gep.ll b/test/Transforms/StraightLineStrengthReduce/slsr-gep.ll index 573c33cb858..b9bb4faf1b4 100644 --- a/test/Transforms/StraightLineStrengthReduce/slsr-gep.ll +++ b/test/Transforms/StraightLineStrengthReduce/slsr-gep.ll @@ -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)*)