[MemCpyOpt] Use the raw i8* dest when optimizing memset+memcpy.
authorAhmed Bougacha <ahmed.bougacha@gmail.com>
Tue, 21 Apr 2015 21:28:33 +0000 (21:28 +0000)
committerAhmed Bougacha <ahmed.bougacha@gmail.com>
Tue, 21 Apr 2015 21:28:33 +0000 (21:28 +0000)
commit9692e30e8b75816b3a966d991ea9eb1e9518292c
treed99b15f4b538448bf74df0a3e175df3499ac895c
parent499bc5faa1426965520676413c6a5d8c0b37e886
[MemCpyOpt] Use the raw i8* dest when optimizing memset+memcpy.

MemIntrinsic::getDest() looks through pointer casts, and using it
directly when building the new GEP+memset results in stuff like:

  %0 = getelementptr i64* %p, i32 16
  %1 = bitcast i64* %0 to i8*
  call ..memset(i8* %1, ...)

instead of the correct:

  %0 = bitcast i64* %p to i8*
  %1 = getelementptr i8* %0, i32 16
  call ..memset(i8* %1, ...)

Instead, use getRawDest, which just gives you the i8* value.
While there, use the memcpy's dest, as it's live anyway.

In most cases, when the optimization triggers, the memset and memcpy
sizes are the same, so the built memset is 0-sized and eliminated.
The problem occurs when they're different.

Fixes a regression caused by r235232: PR23300.

llvm-svn: 235419
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
llvm/test/Transforms/MemCpyOpt/memset-memcpy-redundant-memset.ll