[LLVMdev] Overzealous PromoteCastOfAllocation

Dan Gohman gohman at apple.com
Mon Sep 22 14:50:49 PDT 2008

On Sep 13, 2008, at 1:07 PM, Matthijs Kooijman wrote:

> Hi Dan,
>> Changing PromoteCastOfAllocation to not replace aggregate allocas  
>> with
>> non-aggregate allocas if they have GEP users sounds reasonable to me.
> This sounds reasonable indeed, but still a bit arbitrary. Haven't  
> figured out
> anything better yet, though.
>> Finding the maximum alignment is sometimes still useful though, so
>> it would be nice to update the alignment field of the alloca even if
>> its type is left unchanged.
> The maximizing of the alignment is done only looking at the type's ABI
> alignment, the actual alignment of the alloca instruction is not used.
> But what you suggest is that if the alloca is casted to some type  
> that has
> higher alignment, you want that higher allignment propagated to the  
> alloca
> instruction? I can see why this is useful, since bitcasting to a  
> type with
> higher alignment can actually produce invalid code, I think? Or how  
> does this
> work exactly?

Oh, ok. So code that takes an alloca, bitcasts the address to a higher
alignment, and then does a load or store at the higher alignment, is
invoking undefined behavior. The alignment attribute on a load or store
is an assertion about the actual alignment of the memory.


More information about the llvm-dev mailing list