[llvm] r309930 - [SelectionDAG] Resolve PR33978.

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 09:25:48 PDT 2017


Merged to 5.0 in r309956.

On Thu, Aug 3, 2017 at 2:38 AM, Simon Dardis via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: sdardis
> Date: Thu Aug  3 02:38:46 2017
> New Revision: 309930
>
> URL: http://llvm.org/viewvc/llvm-project?rev=309930&view=rev
> Log:
> [SelectionDAG] Resolve PR33978.
>
> rL306209 taught SelectionDAG how to add the dereferenceable flag when
> expanding memcpy and memmove. The fix however contained a nit where
> the offset + size was constructed as an APInt of PointerSize rather
> than PointerSizeInBits.
>
> This lead to isDereferenceableAndAlignedPointer() get truncated values or
> values which would be sign extended within that function leading to
> incorrect results.
>
> Thanks to Alex Crichton for reporting the issue!
>
> This resolves PR33978.
>
> Reviewers: inouehrs
>
> Differential Revision: https://reviews.llvm.org/D36236
>
> Added:
>     llvm/trunk/test/CodeGen/Mips/pr33978.ll
> Modified:
>     llvm/trunk/lib/CodeGen/MachineInstr.cpp
>
> Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=309930&r1=309929&r2=309930&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Thu Aug  3 02:38:46 2017
> @@ -581,10 +581,8 @@ bool MachinePointerInfo::isDereferenceab
>    if (BasePtr == nullptr)
>      return false;
>
> -  return isDereferenceableAndAlignedPointer(BasePtr, 1,
> -                                            APInt(DL.getPointerSize(),
> -                                                  Offset + Size),
> -                                            DL);
> +  return isDereferenceableAndAlignedPointer(
> +      BasePtr, 1, APInt(DL.getPointerSizeInBits(), Offset + Size), DL);
>  }
>
>  /// getConstantPool - Return a MachinePointerInfo record that refers to the
>
> Added: llvm/trunk/test/CodeGen/Mips/pr33978.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/pr33978.ll?rev=309930&view=auto
> ==============================================================================
> --- llvm/trunk/test/CodeGen/Mips/pr33978.ll (added)
> +++ llvm/trunk/test/CodeGen/Mips/pr33978.ll Thu Aug  3 02:38:46 2017
> @@ -0,0 +1,20 @@
> +; RUN: llc -march=mips -mcpu=mips32r2 < %s -o /dev/null
> +
> +; Test that SelectionDAG does not crash during DAGCombine when two pointers
> +; to the stack match with differing bases and offsets when expanding memcpy.
> +; This could result in one of the pointers being considered dereferenceable
> +; and other not.
> +
> +define void @foo(i8*) {
> +start:
> +  %a = alloca [22 x i8]
> +  %b = alloca [22 x i8]
> +  %c = bitcast [22 x i8]* %a to i8*
> +  %d = getelementptr inbounds [22 x i8], [22 x i8]* %b, i32 0, i32 2
> +  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %c, i8* %d, i32 20, i32 1, i1 false)
> +  %e = getelementptr inbounds [22 x i8], [22 x i8]* %b, i32 0, i32 6
> +  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* %e, i32 12, i32 1, i1 false)
> +  ret void
> +}
> +
> +declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list