Duncan Sands
2008-Jul-10 12:40 UTC
[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.
Nicolas Capens
2008-Jul-10 12:46 UTC
[LLVMdev] InstructionCombining forgets alignment of globals
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 thisis> 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.
David Greene
2008-Jul-10 16:19 UTC
[LLVMdev] InstructionCombining forgets alignment of globals
On Thursday 10 July 2008 07:46, Nicolas Capens wrote:> 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.Nicolas, Where are you explicitly calling setAlignment? From llvm-gcc code? -Dave
Maybe Matching Threads
- [LLVMdev] InstructionCombining forgets alignment of globals
- [LLVMdev] InstructionCombining forgets alignment of globals
- [LLVMdev] InstructionCombining forgets alignment of globals
- [LLVMdev] InstructionCombining forgets alignment of globals
- [LLVMdev] TargetData::getPreferredAlignment(const GlobalVariable *GV) is strange ...