Fix a really bad miscompile introduced in r216865 - the else-if logic
authorChandler Carruth <chandlerc@gmail.com>
Mon, 1 Sep 2014 10:09:18 +0000 (10:09 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Mon, 1 Sep 2014 10:09:18 +0000 (10:09 +0000)
commit1faa4454761c5aee2854ab127ffc0dde877b3982
tree495c026ffcd58ee417d23f97e95fb3fd48d358f4
parent35b114fe182430dcb42df5d21ae9a28993ee46d6
Fix a really bad miscompile introduced in r216865 - the else-if logic
chain became completely broken here as *all* intrinsic users ended up
being skipped, and the ones that seemed to be singled out were actually
the exact wrong set.

This is a great example of why long else-if chains can be easily
confusing. Switch the entire code to use early exits and early continues
to have simpler (and more importantly, correct) logic here, as well as
fixing the reversed logic for detecting and continuing on lifetime
intrinsics.

I've also significantly cleaned up the test case and added another test
case demonstrating an example where the optimization is not (trivially)
safe to perform.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216871 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/MemCpyOptimizer.cpp
test/Transforms/MemCpyOpt/memcpy-to-memset-with-lifetimes.ll