[LLVMdev] InstructionCombining forgets alignment of globals

Nicolas Capens nicolas at capens.net
Thu Jul 10 05:46:57 PDT 2008


Hi Duncan,

I see. I didn't know GlobalValue had a method for changing the alignment
(and that 0 meant natural alignment). Explicitly calling setAlignment works
like a charm.

So it's not an LLVM bug.

Thanks,

Nicolas


-----Original Message-----
From: Duncan Sands [mailto:baldrick at free.fr] 
Sent: Thursday, 10 July, 2008 14:41
To: llvmdev at cs.uiuc.edu
Cc: Nicolas Capens
Subject: Re: [LLVMdev] InstructionCombining forgets alignment of globals

Hi Nicolas,

>   if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
> 
>     unsigned Align = GV->getAlignment();
> 
>     if (Align == 0 && TD && GV->getType()->getElementType()->isSized()) 
> 
>       Align = TD->getPrefTypeAlignment(GV->getType()->getElementType());
>
> It assumes that global values are always optimally aligned. I think this
is
> incorrect and the bottom two lines should be removed.

I don't understand - if Align is zero it means that GV was marked
as having preferred alignment (that's what Align == 0 means), so
it is not wrong to change it explicitly to the preferred alignment
for the target.

Ciao,

Duncan.




More information about the llvm-dev mailing list