Ticket #6158 (closed bug: fixed)

Opened 11 months ago

Last modified 11 months ago

GHC Causes opt to crash under LLVM 3.1 due to non const memcpy offset

Reported by: Axman6 Owned by: dterei
Priority: normal Milestone:
Component: Compiler (LLVM) Version: 7.4.1
Keywords: llvm memcpy Cc: axman6@…
Operating System: MacOS X Architecture: x86_64 (amd64)
Type of failure: Compile-time crash Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by simonmar) (diff)

Under LLVM 3.1, opt is crashing when compiling code produced by GHC which makes calls to memcpy. After talking to the guys in #llvm they informed me that memcpy needs its alignment argument to be a const value, not from a value in a register. An example of the crash log:

alignment argument of memory intrinsics must be a constant int
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %lnfVC, i8* %lnfVE, i64 %lnfVF, i32 %lnfVG, i1 false)
alignment argument of memory intrinsics must be a constant int
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %lnfWc, i8* %lnfWe, i64 %lnfWf, i32 %lnfWg, i1 false)
alignment argument of memory intrinsics must be a constant int
  call void @llvm.memmove.p0i8.p0i8.i64(i8* %lnfWk, i8* %lnfWm, i64 %lnfWn, i32 %lnfWo, i1 false)
alignment argument of memory intrinsics must be a constant int
  call void @llvm.memmove.p0i8.p0i8.i64(i8* %lnfWJ, i8* %lnfWL, i64 %lnfWM, i32 %lnfWN, i1 false)
Broken module found, compilation aborted!
0  opt               0x000000010cec4be7 llvm::sys::ThreadLocal<llvm::PrettyStackTraceEntry const>::~ThreadLocal() + 6113
1  opt               0x000000010cec4eee llvm::sys::ThreadLocal<llvm::PrettyStackTraceEntry const>::~ThreadLocal() + 6888
2  libsystem_c.dylib 0x00007fff8dabacfa _sigtramp + 26
3  libsystem_c.dylib 000000000000000000 _sigtramp + 18446603338139325216
4  opt               0x000000010cec4dfc llvm::sys::ThreadLocal<llvm::PrettyStackTraceEntry const>::~ThreadLocal() + 6646
5  opt               0x000000010ce9865a llvm::StringMap<llvm::Value*, llvm::MallocAllocator>::clear() + 8942
6  opt               0x000000010ce975cd llvm::StringMap<llvm::Value*, llvm::MallocAllocator>::clear() + 4705
7  opt               0x000000010ce8b50b llvm::PassRegistrationListener::passEnumerate(llvm::PassInfo const*) + 12531
8  opt               0x000000010ce8b704 llvm::PassRegistrationListener::passEnumerate(llvm::PassInfo const*) + 13036
9  opt               0x000000010ce8b848 llvm::PassRegistrationListener::passEnumerate(llvm::PassInfo const*) + 13360
10 opt               0x000000010ce8bb28 llvm::PassRegistrationListener::passEnumerate(llvm::PassInfo const*) + 14096
11 opt               0x000000010ce8bf27 llvm::PassRegistrationListener::passEnumerate(llvm::PassInfo const*) + 15119
12 opt               0x000000010cc7a708 llvm::DenseMap<llvm::BasicBlock*, unsigned int, llvm::DenseMapInfo<llvm::BasicBlock*>, llvm::DenseMapInfo<unsigned int> >::init(unsigned int) + 4866
13 opt               0x000000010cc76364
Stack dump:
0.	Program arguments: opt mmulttest.ll -o /var/folders/0n/bjp22m948xlgtl006s6kwyj00000gv/T/ghc87286_0/ghc87286_0.bc -O3 -std-compile-opts -time-passes -loop-unroll 
1.	Running pass 'Function Pass Manager' on module 'mmulttest.ll'.
2.	Running pass 'Module Verifier' on function '@seo9_info'

Attachments

testcase.hs Download (360 bytes) - added by Axman6 11 months ago.
A minimal test case which produces the problem
testcase.ll Download (45.9 KB) - added by Axman6 11 months ago.
LLVM IR from compiling testcase.hs compiled with ghc -O2 -fllvm testcase.hs

Change History

Changed 11 months ago by simonmar

  • difficulty set to Unknown
  • description modified (diff)

Changed 11 months ago by Axman6

A minimal test case which produces the problem

Changed 11 months ago by Axman6

LLVM IR from compiling testcase.hs compiled with ghc -O2 -fllvm testcase.hs

Changed 11 months ago by Axman6

  • cc axman6@… added

Changed 11 months ago by simonmar

David, any chance you could look at this please?

Changed 11 months ago by dterei

Yes, not sure when but hopefully soon.

Changed 11 months ago by davidterei@…

commit 41b37a233e92b3f7df07f1d8d4240e80643dff96

Author: David Terei <davidterei@gmail.com>
Date:   Mon Jun 25 00:51:47 2012 -0700

    Fix #6158. LLVM 3.1 doesn't like certain constructions that 3.0 and
    earlier did, so we avoid them.

 compiler/llvmGen/LlvmCodeGen/CodeGen.hs |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

Changed 11 months ago by dterei

  • status changed from new to closed
  • resolution set to fixed

OK fixed. Damn LLVM doesn't like this code anymore:

%a = i32 1
call ccc llvm.memcpy.p0i8.p0i8.i64( i8* %x, i8* %y, i64 %z, i32 %a, i1 0)

As while the alignment (a) is constant the fact it's in a variable throws LLVM off in 3.1. A work around for now is to run LLVM's constant propigation pass at the very start to inline the variable. e.g do this:

$ ghc --make testcase.hs -fllvm -O2 -optlo-constprop -optlo-O3

and it should compile fine.

Note: See TracTickets for help on using tickets.