This fixes http://llvm.org/bugs/show_bug.cgi?id=20673
Diff Detail
Event Timeline
For platforms with suppport for unaligned access, this is always a win, isn't it? I.e. independent of the correct alignment of the pointers.
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.
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
955 | Isn't the RHS just isPowerOf2_64? Also, '8' sounds awfully target specific. I doubt this is the correct number for the MSP430 target. | |
956–958 | This seems strangely formatted, consider running clang-format over these lines. | |
960 | There is no need to manually strength-reduce multiplication by eight. Also, this can never fail. | |
962–965 | Perhaps: 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.
lib/Transforms/Utils/SimplifyLibCalls.cpp | ||
---|---|---|
955 | 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. | |
956–958 | 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. | |
960 | Oh, I just took the "Len << 3" from InstCombiner::SimplifyMemTransfer. Will fix. :) | |
962–965 | This too I just took from InstCombiner::SimplifyMemTransfer. I will use what you suggest instead. |
Addressed all review comments except the "Len <= 8" check, because I don't know what should be used instead.
Thanks mcrosier, will fix!
(I'm curious: how come this wasn't caught when I ran the tests? Are these names case-insensitive?)
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.
Chad
Eelis,
Do you have commit rights? If not, I'd be happy to commit the patch on your behalf.
Chad
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 :)
@majnemer: David, would you mind giving this a once over before I commit? This has been sitting for many months..
Isn't the RHS just isPowerOf2_64?
Also, '8' sounds awfully target specific. I doubt this is the correct number for the MSP430 target.