[PATCH] Handle address spaces in TargetTransformInfo

Eli Friedman eli.friedman at gmail.com
Wed Aug 21 17:41:47 PDT 2013


I'm pretty sure the test passes without your change...

-Eli


On Wed, Aug 21, 2013 at 1:01 PM, Matt Arsenault
<Matthew.Arsenault at amd.com>wrote:

> http://llvm-reviews.chandlerc.com/D1464
>
> Files:
>   lib/Analysis/TargetTransformInfo.cpp
>   test/Transforms/Inline/ptr-diff.ll
>
> Index: lib/Analysis/TargetTransformInfo.cpp
> ===================================================================
> --- lib/Analysis/TargetTransformInfo.cpp
> +++ lib/Analysis/TargetTransformInfo.cpp
> @@ -265,26 +265,34 @@
>        // Otherwise, the default basic cost is used.
>        return TCC_Basic;
>
> -    case Instruction::IntToPtr:
> +    case Instruction::IntToPtr: {
> +      if (!DL)
> +        return TCC_Basic;
> +
>        // An inttoptr cast is free so long as the input is a legal integer
> type
>        // which doesn't contain values outside the range of a pointer.
> -      if (DL && DL->isLegalInteger(OpTy->getScalarSizeInBits()) &&
> -          OpTy->getScalarSizeInBits() <= DL->getPointerSizeInBits())
> +      unsigned OpSize = OpTy->getScalarSizeInBits();
> +      if (DL->isLegalInteger(OpSize) &&
> +          OpSize <= DL->getPointerTypeSizeInBits(Ty))
>          return TCC_Free;
>
>        // Otherwise it's not a no-op.
>        return TCC_Basic;
> +    }
> +    case Instruction::PtrToInt: {
> +      if (!DL)
> +        return TCC_Basic;
>
> -    case Instruction::PtrToInt:
>        // A ptrtoint cast is free so long as the result is large enough to
> store
>        // the pointer, and a legal integer type.
> -      if (DL && DL->isLegalInteger(Ty->getScalarSizeInBits()) &&
> -          Ty->getScalarSizeInBits() >= DL->getPointerSizeInBits())
> +      unsigned DestSize = Ty->getScalarSizeInBits();
> +      if (DL->isLegalInteger(DestSize) &&
> +          DestSize >= DL->getPointerTypeSizeInBits(OpTy))
>          return TCC_Free;
>
>        // Otherwise it's not a no-op.
>        return TCC_Basic;
> -
> +    }
>      case Instruction::Trunc:
>        // trunc to a native type is free (assuming the target has compare
> and
>        // shift-right of the same width).
> Index: test/Transforms/Inline/ptr-diff.ll
> ===================================================================
> --- test/Transforms/Inline/ptr-diff.ll
> +++ test/Transforms/Inline/ptr-diff.ll
> @@ -56,6 +56,34 @@
>    ret i32 %t
>  }
>
> +define i32 @outer_inttoptr_as_cost(i32 addrspace(1)* %ptr) {
> +; CHECK-LABEL: @outer_inttoptr_as_cost(
> +; CHECK: call
> +; CHECK: ret i32
> +  %ptr1 = getelementptr inbounds i32 addrspace(1)* %ptr, i32 0
> +  %ptr2 = getelementptr inbounds i32 addrspace(1)* %ptr, i32 42
> +  %int1 = ptrtoint i32 addrspace(1)* %ptr1 to i32
> +  %int2 = ptrtoint i32 addrspace(1)* %ptr2 to i32
> +  %result = call i32 @inner_inttoptr_as_cost(i32 %int1, i32 %int2)
> +  ret i32 %result
> +}
> +
> +; Test that the operation cost for inttoptr is hit
> +define i32 @inner_inttoptr_as_cost(i32 %begin, i32 %end) {
> +  %distance = sub i32 %end, %begin
> +  %begin.p = inttoptr i32 %begin to i32 addrspace(1)*
> +  %end.p = inttoptr i32 %end to i32 addrspace(1)*
> +  %icmp = icmp sle i32 %distance, 42
> +  br i1 %icmp, label %then, label %else
> +
> +then:
> +  ret i32 3
> +
> +else:
> +  %t = load i32 addrspace(1)* %begin.p
> +  ret i32 %t
> +}
> +
>  ; Make sure that assertion isn't hit when ptrtoint is used with an
>  ; integer size different from the pointer size
>  define i32 @outer1_ptrtoint_larger() {
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130821/ea4470e6/attachment.html>


More information about the llvm-commits mailing list