[PATCH] Constant fold ptrtoint + compare with address spaces

Eli Friedman eli.friedman at gmail.com
Mon Sep 30 13:47:19 PDT 2013


LGTM.

-Eli


On Fri, Sep 27, 2013 at 3:46 PM, Matt Arsenault
<Matthew.Arsenault at amd.com>wrote:

> http://llvm-reviews.chandlerc.com/D1777
>
> Files:
>   lib/Transforms/InstCombine/InstCombineCompares.cpp
>   test/Transforms/InstCombine/cast_ptr.ll
>
> Index: lib/Transforms/InstCombine/InstCombineCompares.cpp
> ===================================================================
> --- lib/Transforms/InstCombine/InstCombineCompares.cpp
> +++ lib/Transforms/InstCombine/InstCombineCompares.cpp
> @@ -1786,7 +1786,7 @@
>    // Turn icmp (ptrtoint x), (ptrtoint/c) into a compare of the input if
> the
>    // integer type is the same size as the pointer type.
>    if (TD && LHSCI->getOpcode() == Instruction::PtrToInt &&
> -      TD->getPointerSizeInBits() == DestTy->getIntegerBitWidth()) {
> +      TD->getPointerTypeSizeInBits(SrcTy) ==
> DestTy->getIntegerBitWidth()) {
>      Value *RHSOp = 0;
>      if (Constant *RHSC = dyn_cast<Constant>(ICI.getOperand(1))) {
>        RHSOp = ConstantExpr::getIntToPtr(RHSC, SrcTy);
> Index: test/Transforms/InstCombine/cast_ptr.ll
> ===================================================================
> --- test/Transforms/InstCombine/cast_ptr.ll
> +++ test/Transforms/InstCombine/cast_ptr.ll
> @@ -27,6 +27,26 @@
>          ret i1 %r
>  }
>
> +; These casts should be folded away.
> +; CHECK-LABEL: @test2_as2_same_int(
> +; CHECK: icmp eq i8 addrspace(2)* %a, %b
> +define i1 @test2_as2_same_int(i8 addrspace(2)* %a, i8 addrspace(2)* %b) {
> +  %tmpa = ptrtoint i8 addrspace(2)* %a to i16
> +  %tmpb = ptrtoint i8 addrspace(2)* %b to i16
> +  %r = icmp eq i16 %tmpa, %tmpb
> +  ret i1 %r
> +}
> +
> +; These casts should be folded away.
> +; CHECK-LABEL: @test2_as2_larger(
> +; CHECK: icmp eq i8 addrspace(2)* %a, %b
> +define i1 @test2_as2_larger(i8 addrspace(2)* %a, i8 addrspace(2)* %b) {
> +  %tmpa = ptrtoint i8 addrspace(2)* %a to i32
> +  %tmpb = ptrtoint i8 addrspace(2)* %b to i32
> +  %r = icmp eq i32 %tmpa, %tmpb
> +  ret i1 %r
> +}
> +
>  ; These casts should also be folded away.
>  ; CHECK-LABEL: @test3(
>  ; CHECK: icmp eq i8* %a, @global
>
> _______________________________________________
> 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/20130930/89c7e429/attachment.html>


More information about the llvm-commits mailing list