[PATCH] Fix a constant folding address space place I missed.
Eli Friedman
eli.friedman at gmail.com
Tue Sep 17 15:41:15 PDT 2013
LGTM.
-Eli
On Thu, Sep 12, 2013 at 2:55 PM, Matt Arsenault
<Matthew.Arsenault at amd.com>wrote:
> If address space 0 was smaller than the address space in a constant
> inttoptr/ptrtoint pair, the wrong mask size would be used.
>
> http://llvm-reviews.chandlerc.com/D1662
>
> Files:
> lib/Analysis/ConstantFolding.cpp
> test/Transforms/InstCombine/constant-fold-address-space-pointer.ll
>
> Index: lib/Analysis/ConstantFolding.cpp
> ===================================================================
> --- lib/Analysis/ConstantFolding.cpp
> +++ lib/Analysis/ConstantFolding.cpp
> @@ -974,10 +974,11 @@
> if (TD && CE->getOpcode() == Instruction::IntToPtr) {
> Constant *Input = CE->getOperand(0);
> unsigned InWidth = Input->getType()->getScalarSizeInBits();
> - if (TD->getPointerTypeSizeInBits(CE->getType()) < InWidth) {
> + unsigned PtrWidth = TD->getPointerTypeSizeInBits(CE->getType());
> + if (PtrWidth < InWidth) {
> Constant *Mask =
> - ConstantInt::get(CE->getContext(),
> APInt::getLowBitsSet(InWidth,
> -
> TD->getPointerSizeInBits()));
> + ConstantInt::get(CE->getContext(),
> + APInt::getLowBitsSet(InWidth, PtrWidth));
> Input = ConstantExpr::getAnd(Input, Mask);
> }
> // Do a zext or trunc to get to the dest size.
> Index: test/Transforms/InstCombine/constant-fold-address-space-pointer.ll
> ===================================================================
> --- test/Transforms/InstCombine/constant-fold-address-space-pointer.ll
> +++ test/Transforms/InstCombine/constant-fold-address-space-pointer.ll
> @@ -74,6 +74,14 @@
> ret i8 ptrtoint (i32 addrspace(3)* inttoptr (i32 257 to i32
> addrspace(3)*) to i8)
> }
>
> +; Address space 0 is too small for the correct mask, should mask with
> +; 64-bits instead of 32
> +define i64 @const_fold_ptrtoint_mask_small_as0() {
> +; CHECK-LABEL: @const_fold_ptrtoint_mask_small_as0(
> +; CHECK: ret i64 -1
> + ret i64 ptrtoint (i32 addrspace(1)* inttoptr (i128 -1 to i32
> addrspace(1)*) to i64)
> +}
> +
> define i32 addrspace(3)* @const_inttoptr() {
> ; CHECK-LABEL: @const_inttoptr(
> ; CHECK-NEXT: ret i32 addrspace(3)* inttoptr (i16 4 to i32 addrspace(3)*)
>
> _______________________________________________
> 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/20130917/444b9560/attachment.html>
More information about the llvm-commits
mailing list