This fixes http://llvm.org/bugs/show_bug.cgi?id=20673
Thanks Joerg, that's a great point!
I don't really know how to do that though. I see that the memcmp code in SelectionDAGBuilder.cpp uses allowsMisalignedMemoryAccesses(), but that function takes an EVT, a type which is not known in Transforms/Utils/SimplifyLibCalls.cpp.
Isn't the RHS just isPowerOf2_64?
Also, '8' sounds awfully target specific. I doubt this is the correct number for the MSP430 target.
This seems strangely formatted, consider running clang-format over these lines.
There is no need to manually strength-reduce multiplication by eight. Also, this can never fail.
Type *LHSPtrTy = IntType->getPointerTo(LHS->getType()->getPointerAddressSpace()); Type *RHSPtrTy = IntType->getPointerTo(RHS->getType()->getPointerAddressSpace());
Thanks David! I'll attach an updated patch, but I don't know how to get rid of the "8" constant.
Oh, I just took this from InstCombiner::SimplifyMemTransfer, which does:
if (Size > 8 || (Size&(Size-1))) return nullptr; // If not 1/2/4/8 bytes, exit.
I'll use isPowerOf2_64 instead, but I'm not sure what I should I use instead of 8.
I like the &&s aligned on the left so I easily see it's a repeated conjunction, but I see that clang-format wants them on the right, so I'll do that.
Oh, I just took the "Len << 3" from InstCombiner::SimplifyMemTransfer. Will fix. :)
This too I just took from InstCombiner::SimplifyMemTransfer. I will use what you suggest instead.
The tests will pass with or without the CHECK-LABEL directives. I believe the FileCheck directives are case-sensitive, but I would have to look at the FileCheck implementation to verify. Regardless, CHECK-LABEL is the preferred style.
I don't think this code should be committed yet, because it does not yet check whether the integer types are available. I tried doing it with:
if (DL && DL->isLegalInteger(Len * 8) && ...
.. but that doesn't work (and the tests fail) because DL is nullptr.
Ah, it wasn't that DL was null, but rather that there were no native integer types specified in the target datalayout for the test. I've added those, and I've also refined the alignment check to take the integer type's preferred alignment into account.
I think it's okay to commit now. Chad: I don't have commit rights, so yes please! Thanks :)