Optimizer issues on Windows

Dear Community,

The ponyc (llvm37 branch) project is facing an issue on Windows:

When optimizations are turned on (llvm 3.7.0-final and more specifically, opt-level 3, BBVectorize, LoopVectorize, SLPVectorize, RerollLoops, LoadCombine + a custom heap to stack pass) writing an object file aborts (on Windows only) with the following fatal error:

“Starting a function before ending the previous one!” at MCStreamer.cpp:407 during LLVMTargetMachineEmitToFile. Verifying the IR with llc raises no errors.

What exact problem is being detected here and how can we get more details on the location in the IR that is causing the problem?

Turning off optimizations successfully writes the object file. This only occurs on Windows, writing object files works fine on Linux and OS X.

Is this a know issue with LLVM 3.7.0-final and how can this be fixed? Is a patch required?

This might be related to https://llvm.org/bugs/show_bug.cgi?id=24374.

Kind regards
Sebastian

I have found that failures such as this (especially given the nature of diagnostic, and the fact that it only crashes on Windows), have often had to do with the a bug in using the C++ Standard collections and iterators. It is worth building this in Debug mode using MSVC++ and using the debug instrumented STL collections and iterators. The implementation of these in MSVC++ is more rigorous than the version provided with G++ and using this in debug mode often diagnoses an iteration error in the code that appears to be harmless in the G++ implementation, but which represents a logical failure in the code that is still wrong, but does not crash.

MartinO

image001.jpg

The bug https://llvm.org/bugs/show_bug.cgi?id=24374 has to do with exceptions on Windows, so it is unrelated unless you are using them.

PR24374 has been fixed on trunk (r247435).

I wouldn't use BBVectorize: Forward Scattering - The Weblog of Nicholas Chapman

Cheers,
   nick

Thanks, we are using exceptions so this might be a problem. Lets see whether the patch that is fixing said bug report fixes our issue!

This got me into thinking. Indeed the problem is related to Windows exceptions, so I am not sure whether the bug reported is actually fixed.

Compiling Pony code (helloworld) that includes no exceptions does work fine (with optimizations). As soon as exceptions on windows come into play, writing the object file dies with the mentioned error in MCStreamer.cpp.

Here are two minimal IR examples (helloworld.ll works, try.ll doesn’t - both verify with llc). The relevant method is @Main_create. Can anyone of you guys confirm the issue with llvm 3.7.0–final, or whether said bug has actually been fixed?

$ ~/llvm/Debug+Asserts/bin/llc try.ll
$ echo $?
0

Are you running on llvm 3.7.0 or ^HEAD?

… Also, it doesn’t appear that you are running on windows…

… Also, it doesn’t appear that you are running on windows…

That is irrelevant for your example because it specifies a target triple:
$ head -n3 try.ll
; ModuleID = 'try'
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"

As to whether or not it fixed the bug:
$ ~/llvm/src/utils/git-svn/git-svnrevert r247435
$ ninja -C ~/llvm/Debug+Asserts llc
[3/3] Linking CXX executable bin/llc
$ ~/llvm/Debug+Asserts/bin/llc try.ll
LLVM ERROR: Starting a function before ending the previous one!

So yes, it seems like r247435 has fixed the bug you are running into.
To answer your other question, r247435 was committed after we branched for
3.7.0

My bad, thanks for clarification.