[cfe-commits] [PATCH] PR12094: set alignment of memory builtins

Eli Friedman eli.friedman at gmail.com
Fri Mar 2 13:28:49 PST 2012


On Fri, Mar 2, 2012 at 1:13 PM, Chris Lattner <clattner at apple.com> wrote:
>
> On Mar 2, 2012, at 12:09 PM, Eli Friedman wrote:
>
>> On Fri, Mar 2, 2012 at 3:57 AM, Jay Foad <jay.foad at gmail.com> wrote:
>>> http://llvm.org/bugs/show_bug.cgi?id=12094
>>>
>>> The attached patch:
>>>
>>> - Makes CGBuiltin.cpp's helper function GetPointeeAlignment into a
>>> proper member of CodeGenFunction and splits it into two:
>>> -- GetPointeeAlignment, which returns alignment as an unsigned, and
>>> -- GetPointeeAlignmentValue, which wraps the result in an llvm::Value
>>> for the convenience of generating ARM NEON intrinsics.
>>>
>>> - Uses GetPointeeAlignment to set a sensible alignment on all memory
>>> intrinsics (memcpy, memset etc.) instead of the conservative default
>>> of 1.
>>
>> I don't think this is really safe; strictly speaking, yes, an int* is
>> required to be appropriately aligned, but in practice neither clang
>> nor gcc has ever tried to enforce that, so making that assumption is
>> going to cause trouble.
>
> Hi Eli,
>
> Is this a vague concern or a specific one?  Even GCC-4.2 has been doing this optimization.  I consider this "fixing a regression compared to GCC", not an innovation in optimization.

I can't point to a specific example off the top of my head, but I do
know that we've suggested switching code that uses unaligned loads to
use memcpy without specifically noting that the type of the pointer
matters.

-Eli




More information about the cfe-commits mailing list