Avoid zero length memset error

Adding a check on buffer lenght to avoid a __warn_memset_zero_len
warning on GCC 4.8.2.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216624 91177308-0d34-0410-b5e6-96231b3b80d8
[FastISel][AArch64] Don't fold instructions too aggressively into the memory operation.

Currently instructions are folded very aggressively into the memory operation,
which can lead to the use of killed operands:
  %vreg1<def> = ADDXri %vreg0<kill>, 2
  %vreg2<def> = LDRBBui %vreg0, 2
  ... = ... %vreg1 ...

This usually happens when the result is also used by another non-memory
instruction in the same basic block, or any instruction in another basic block.

If the computed address is used by only memory operations in the same basic
block, then it is safe to fold them. This is because all memory operations will
fold the address computation and the original computation will never be emitted.

This fixes rdar://problem/18142857.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216629 91177308-0d34-0410-b5e6-96231b3b80d8
Fix unaligned reads/writes in X86JIT and RuntimeDyldELF.

Summary:
Introduce support::ulittleX_t::ref type to Support/Endian.h and use it in x86 JIT
to enforce correct endianness and fix unaligned accesses.

Test Plan: regression test suite

Reviewers: lhames

Subscribers: ributzka, llvm-commits

Differential Revision: http://reviews.llvm.org/D5011

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216631 91177308-0d34-0410-b5e6-96231b3b80d8
Revert "[FastISel][AArch64] Don't fold instructions too aggressively into the memory operation."

Quentin pointed out that this is not the correct approach and there is a better and easier solution.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216632 91177308-0d34-0410-b5e6-96231b3b80d8
[FastISel]

Currently instructions are folded very aggressively for AArch64 into the memory
operation, which can lead to the use of killed operands:
  %vreg1<def> = ADDXri %vreg0<kill>, 2
  %vreg2<def> = LDRBBui %vreg0, 2
  ... = ... %vreg1 ...

This usually happens when the result is also used by another non-memory
instruction in the same basic block, or any instruction in another basic block.

This fix teaches hasTrivialKill to not only check the LLVM IR that the value has
a single use, but also to check if the register that represents that value has
already been used. This can happen when the instruction with the use was folded
into another instruction (in this particular case a load instruction).

This fixes rdar://problem/18142857.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216634 91177308-0d34-0410-b5e6-96231b3b80d8
[FastISel] Undo phi node updates when falling-back to SelectionDAG.

The included test case would fail, because the MI PHI node would have two
operands from the same predecessor.

This problem occurs when a switch instruction couldn't be selected. This happens
always, because there is no default switch support for FastISel to begin with.

The problem was that FastISel would first add the operand to the PHI nodes and
then fall-back to SelectionDAG, which would then in turn add the same operands
to the PHI nodes again.

This fix removes these duplicate PHI node operands by reseting the
PHINodesToUpdate to its original state before FastISel tried to select the
instruction.

This fixes <rdar://problem/18155224>.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216640 91177308-0d34-0410-b5e6-96231b3b80d8
InstSimplify: Move a transform from InstCombine to InstSimplify

Several combines involving icmp (shl C2, %X) C1 can be simplified
without introducing any new instructions.  Move them to InstSimplify;
while we are at it, make them more powerful.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216642 91177308-0d34-0410-b5e6-96231b3b80d8
[x86] Clean up some tests to use FileCheck and combine two into a single
file.

Changing code that is covered by these tests is just too hard to debug
currently, and now it will be clear the nature of the changes.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216643 91177308-0d34-0410-b5e6-96231b3b80d8
[x86] Inline an SSE4 helper function for INSERT_VECTOR_ELT lowering, no
functionality changed.

Separating this into two functions wasn't helping. There was a decent
amount of boilerplate duplicated, and some subsequent refactorings here
will pull even more common code out.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216644 91177308-0d34-0410-b5e6-96231b3b80d8
[x86] Hoist conditions from *every single if* in this routine to
a single early exit.

And factor the subsequent cast<> from all but one block into a single
variable.

No functionality changed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216645 91177308-0d34-0410-b5e6-96231b3b80d8
[x86] Fix whitespace and formatting around this function with
clang-format, no functionality changed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216646 91177308-0d34-0410-b5e6-96231b3b80d8
MC: Don't crash when the COFF section limit is reached

I've decided not to commit a test, it takes 2.5 seconds to run on my an
incredibly strong machine.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216647 91177308-0d34-0410-b5e6-96231b3b80d8
[MCJIT] Fix format specifiers for debug output in RuntimeDyld.

More work on http://llvm.org/PR20640



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216648 91177308-0d34-0410-b5e6-96231b3b80d8
Test commit.  Fix whitespace from a previous patch of mine.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216650 91177308-0d34-0410-b5e6-96231b3b80d8
Generate CMN when comparing a short int with minus

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216651 91177308-0d34-0410-b5e6-96231b3b80d8
Fix: SLPVectorizer tried to move an instruction which was replaced by a vector instruction.

For a detailed description of the problem see the comment in the test file.
The problematic moveBefore() calls are not required anymore because the new
scheduling algorithm ensures a correct ordering anyway.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216656 91177308-0d34-0410-b5e6-96231b3b80d8
InstCombine: Remove redundant combines

InstSimplify already handles icmp (X+Y), X (and things like it)
appropriately.  The first thing that InstCombine does is run
InstSimplify on the instruction.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216659 91177308-0d34-0410-b5e6-96231b3b80d8
[PBQP] Only output debug information when requested

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216660 91177308-0d34-0410-b5e6-96231b3b80d8
Silence a -Wsign-compare warning. NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216666 91177308-0d34-0410-b5e6-96231b3b80d8
Minor spelling correction.

Reviewers: adasgupt, jverma, sidneym

Differential Revision: http://reviews.llvm.org/D5025

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216667 91177308-0d34-0410-b5e6-96231b3b80d8