Nicolas Capens
2008-Jul-10 10:18 UTC
[LLVMdev] InstructionCombining forgets alignment of globals
Hi all, The InstructionCombining pass causes alignment of globals to be ignored. I've attached a replacement of Fibonacci.cpp which reproduces this (I used 2.3 release). Here's the x86 code it produces: 03C20019 movaps xmm0,xmmword ptr ds:[164E799h] 03C20020 mulps xmm0,xmmword ptr ds:[164E79Ah] 03C20027 movaps xmmword ptr ds:[164E799h],xmm0 03C2002E mov esp,ebp 03C20030 pop ebp 03C20031 ret All three SSE instructions will generate a fault for accessing unaligned memory. Disabling InstructionCombining gives me the following correct code: 03B10010 push ebp 03B10011 mov ebp,esp 03B10013 and esp,0FFFFFFF0h 03B10019 movups xmm0,xmmword ptr ds:[164E79Ah] 03B10020 movups xmm1,xmmword ptr ds:[164E799h] 03B10027 mulps xmm1,xmm0 03B1002A movups xmmword ptr ds:[164E799h],xmm1 03B10031 mov esp,ebp 03B10033 pop ebp 03B10034 ret Unless I'm missing something this is quite clearly a bug. I'll give it a try to locate the faulty code but all help is very welcome. Cheers, Nicolas Capens -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080710/baa42ec1/attachment.html> -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: fibonacci.cpp URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080710/baa42ec1/attachment.ksh>
Nicolas Capens
2008-Jul-10 11:18 UTC
[LLVMdev] InstructionCombining forgets alignment of globals
I think I found it. In InstCombiner::ComputeMaskedBits we have the following lines: 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. However, I do think it's useful to specify the alignment at the time of GlobalValue creation, so I propose to add a constructor with an Alignment argument. From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Nicolas Capens Sent: Thursday, 10 July, 2008 12:18 To: 'LLVM Developers Mailing List' Subject: [LLVMdev] InstructionCombining forgets alignment of globals Hi all, The InstructionCombining pass causes alignment of globals to be ignored. I've attached a replacement of Fibonacci.cpp which reproduces this (I used 2.3 release). Here's the x86 code it produces: 03C20019 movaps xmm0,xmmword ptr ds:[164E799h] 03C20020 mulps xmm0,xmmword ptr ds:[164E79Ah] 03C20027 movaps xmmword ptr ds:[164E799h],xmm0 03C2002E mov esp,ebp 03C20030 pop ebp 03C20031 ret All three SSE instructions will generate a fault for accessing unaligned memory. Disabling InstructionCombining gives me the following correct code: 03B10010 push ebp 03B10011 mov ebp,esp 03B10013 and esp,0FFFFFFF0h 03B10019 movups xmm0,xmmword ptr ds:[164E79Ah] 03B10020 movups xmm1,xmmword ptr ds:[164E799h] 03B10027 mulps xmm1,xmm0 03B1002A movups xmmword ptr ds:[164E799h],xmm1 03B10031 mov esp,ebp 03B10033 pop ebp 03B10034 ret Unless I'm missing something this is quite clearly a bug. I'll give it a try to locate the faulty code but all help is very welcome. Cheers, Nicolas Capens -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080710/ac6020d5/attachment.html>
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.
David Greene
2008-Jul-10 16:17 UTC
[LLVMdev] InstructionCombining forgets alignment of globals
On Thursday 10 July 2008 05:18, Nicolas Capens wrote:> Hi all, > > > > The InstructionCombining pass causes alignment of globals to be ignored.> All three SSE instructions will generate a fault for accessing unaligned > memory. Disabling InstructionCombining gives me the following correct code:I'm looking at a very similar bug in a test here. I've tracked it down to some problem in ComputeMaskedBits but I haven't been able to get further than that. I'm trying to reduce the testcase (hence the thread about Function cloning). -Dave
Maybe Matching Threads
- [LLVMdev] InstructionCombining forgets alignment of globals
- [LLVMdev] Spilled variables using unaligned moves
- [LLVMdev] Spilled variables using unaligned moves
- [LLVMdev] Spilled variables using unaligned moves
- [LLVMdev] Spilled variables using unaligned moves