Index: lib/Transforms/InstCombine/InstCombineCasts.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCasts.cpp +++ lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1719,7 +1719,7 @@ // cast to be exposed to other transforms. unsigned AS = CI.getAddressSpace(); if (CI.getOperand(0)->getType()->getScalarSizeInBits() != - DL.getPointerSizeInBits(AS)) { + DL.getIndexSizeInBits(AS)) { Type *Ty = DL.getIntPtrType(CI.getContext(), AS); if (CI.getType()->isVectorTy()) // Handle vectors of pointers. Ty = VectorType::get(Ty, CI.getType()->getVectorNumElements()); Index: test/Transforms/InstCombine/ptr-int-cast_custom_gep.ll =================================================================== --- /dev/null +++ test/Transforms/InstCombine/ptr-int-cast_custom_gep.ll @@ -0,0 +1,77 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -instcombine -S | FileCheck %s +target datalayout = "E-p:40:64:64:32-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128" + +define i1 @test1(i32 *%x) nounwind { +; CHECK-LABEL: @test1( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = ptrtoint i32* [[X:%.*]] to i32 +; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[TMP0]], 1 +; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i32 [[TMP1]], 0 +; CHECK-NEXT: ret i1 [[TMP2]] +; +entry: + %0 = ptrtoint i32* %x to i1 + ret i1 %0 +} + +define i32* @test2(i128 %x) nounwind { +; CHECK-LABEL: @test2( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = trunc i128 [[X:%.*]] to i32 +; CHECK-NEXT: [[TMP1:%.*]] = inttoptr i32 [[TMP0]] to i32* +; CHECK-NEXT: ret i32* [[TMP1]] +; +entry: + %0 = inttoptr i128 %x to i32* + ret i32* %0 +} + +; PR3574 +define i64 @f0(i32 %a0) nounwind { +; CHECK-LABEL: @f0( +; CHECK-NEXT: [[T1:%.*]] = zext i32 [[A0:%.*]] to i64 +; CHECK-NEXT: ret i64 [[T1]] +; + %t0 = inttoptr i32 %a0 to i8* + %t1 = ptrtoint i8* %t0 to i64 + ret i64 %t1 +} + +define <4 x i32> @test4(<4 x i8*> %arg) nounwind { +; CHECK-LABEL: @test4( +; CHECK-NEXT: [[P1:%.*]] = ptrtoint <4 x i8*> [[ARG:%.*]] to <4 x i32> +; CHECK-NEXT: ret <4 x i32> [[P1]] +; + %p1 = ptrtoint <4 x i8*> %arg to <4 x i32> + ret <4 x i32> %p1 +} + +define <4 x i128> @test5(<4 x i8*> %arg) nounwind { +; CHECK-LABEL: @test5( +; CHECK-NEXT: [[TMP1:%.*]] = ptrtoint <4 x i8*> [[ARG:%.*]] to <4 x i32> +; CHECK-NEXT: [[P1:%.*]] = zext <4 x i32> [[TMP1]] to <4 x i128> +; CHECK-NEXT: ret <4 x i128> [[P1]] +; + %p1 = ptrtoint <4 x i8*> %arg to <4 x i128> + ret <4 x i128> %p1 +} + +define <4 x i8*> @test6(<4 x i32> %arg) nounwind { +; CHECK-LABEL: @test6( +; CHECK-NEXT: [[P1:%.*]] = inttoptr <4 x i32> [[ARG:%.*]] to <4 x i8*> +; CHECK-NEXT: ret <4 x i8*> [[P1]] +; + %p1 = inttoptr <4 x i32> %arg to <4 x i8*> + ret <4 x i8*> %p1 +} + +define <4 x i8*> @test7(<4 x i128> %arg) nounwind { +; CHECK-LABEL: @test7( +; CHECK-NEXT: [[TMP1:%.*]] = trunc <4 x i128> [[ARG:%.*]] to <4 x i32> +; CHECK-NEXT: [[P1:%.*]] = inttoptr <4 x i32> [[TMP1]] to <4 x i8*> +; CHECK-NEXT: ret <4 x i8*> [[P1]] +; + %p1 = inttoptr <4 x i128> %arg to <4 x i8*> + ret <4 x i8*> %p1 +} Index: test/Transforms/SeparateConstOffsetFromGEP/custom_dl.ll =================================================================== --- /dev/null +++ test/Transforms/SeparateConstOffsetFromGEP/custom_dl.ll @@ -0,0 +1,51 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -S -separate-const-offset-from-gep -reassociate-geps-verify-no-dead-code -gvn < %s | FileCheck %s + +target datalayout = "e-m:m-p:40:64:64:32-i32:32-i16:16-i8:8-n32" + +@array = internal addrspace(4) constant [4096 x [32 x float]] zeroinitializer, align 4 + +define void @sum_of_array(i32 %x, i32 %y, float addrspace(1)* nocapture %output) { +; CHECK-LABEL: @sum_of_array( +; CHECK-NEXT: [[TMP:%.*]] = sext i32 [[Y:%.*]] to i64 +; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[X:%.*]] to i64 +; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds [4096 x [32 x float]], [4096 x [32 x float]] addrspace(4)* @array, i32 0, i32 [[X]], i32 [[Y]] +; CHECK-NEXT: [[TMP4:%.*]] = load float, float addrspace(4)* [[TMP2]], align 4 +; CHECK-NEXT: [[TMP5:%.*]] = fadd float [[TMP4]], 0.000000e+00 +; CHECK-NEXT: [[TMP6:%.*]] = add i32 [[Y]], 1 +; CHECK-NEXT: [[TMP7:%.*]] = sext i32 [[TMP6]] to i64 +; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds [4096 x [32 x float]], [4096 x [32 x float]] addrspace(4)* @array, i32 0, i32 [[X]], i32 [[TMP6]] +; CHECK-NEXT: [[TMP10:%.*]] = load float, float addrspace(4)* [[TMP8]], align 4 +; CHECK-NEXT: [[TMP11:%.*]] = fadd float [[TMP5]], [[TMP10]] +; CHECK-NEXT: [[TMP12:%.*]] = add i32 [[X]], 1 +; CHECK-NEXT: [[TMP13:%.*]] = sext i32 [[TMP12]] to i64 +; CHECK-NEXT: [[TMP14:%.*]] = getelementptr inbounds [4096 x [32 x float]], [4096 x [32 x float]] addrspace(4)* @array, i32 0, i32 [[TMP12]], i32 [[Y]] +; CHECK-NEXT: [[TMP16:%.*]] = load float, float addrspace(4)* [[TMP14]], align 4 +; CHECK-NEXT: [[TMP17:%.*]] = fadd float [[TMP11]], [[TMP16]] +; CHECK-NEXT: [[TMP18:%.*]] = getelementptr inbounds [4096 x [32 x float]], [4096 x [32 x float]] addrspace(4)* @array, i32 0, i32 [[TMP12]], i32 [[TMP6]] +; CHECK-NEXT: [[TMP20:%.*]] = load float, float addrspace(4)* [[TMP18]], align 4 +; CHECK-NEXT: [[TMP21:%.*]] = fadd float [[TMP17]], [[TMP20]] +; CHECK-NEXT: store float [[TMP21]], float addrspace(1)* [[OUTPUT:%.*]], align 4 +; CHECK-NEXT: ret void +; + %tmp = sext i32 %y to i64 + %tmp1 = sext i32 %x to i64 + %tmp2 = getelementptr inbounds [4096 x [32 x float]], [4096 x [32 x float]] addrspace(4)* @array, i64 0, i64 %tmp1, i64 %tmp + %tmp4 = load float, float addrspace(4)* %tmp2, align 4 + %tmp5 = fadd float %tmp4, 0.000000e+00 + %tmp6 = add i32 %y, 1 + %tmp7 = sext i32 %tmp6 to i64 + %tmp8 = getelementptr inbounds [4096 x [32 x float]], [4096 x [32 x float]] addrspace(4)* @array, i64 0, i64 %tmp1, i64 %tmp7 + %tmp10 = load float, float addrspace(4)* %tmp8, align 4 + %tmp11 = fadd float %tmp5, %tmp10 + %tmp12 = add i32 %x, 1 + %tmp13 = sext i32 %tmp12 to i64 + %tmp14 = getelementptr inbounds [4096 x [32 x float]], [4096 x [32 x float]] addrspace(4)* @array, i64 0, i64 %tmp13, i64 %tmp + %tmp16 = load float, float addrspace(4)* %tmp14, align 4 + %tmp17 = fadd float %tmp11, %tmp16 + %tmp18 = getelementptr inbounds [4096 x [32 x float]], [4096 x [32 x float]] addrspace(4)* @array, i64 0, i64 %tmp13, i64 %tmp7 + %tmp20 = load float, float addrspace(4)* %tmp18, align 4 + %tmp21 = fadd float %tmp17, %tmp20 + store float %tmp21, float addrspace(1)* %output, align 4 + ret void +}