Thanks for the suggestion! Unfortunately,
1) it also inserts calls to _Unwind_SjLj_Register/_Unwind_SjLj_Unregister
2) it still inserts phis, and also the equivalent for memory-based synchronisation in landingpads:
Lj15:
%tmp.6.1.reg2mem.0 = phi i32 [ %reg.1_66, %Lj47 ], [ %reg.1_66, %Lj46 ], [ %reg.1_66, %Lj45 ], [ %reg.1_66, %Lj44 ], [ %reg.1_66, %Lj43 ], [ %reg.1_66, %Lj42 ], [ %reg.1_66, %Lj41 ], [ %reg.1_66, %Lj40 ], [ %reg.1_66, %Lj32 ], [ %reg.1_66, %Lj38 ], [ %reg.1_6
6, %Lj37 ], [ %reg.1_66, %Lj36 ], [ %reg.1_66, %Lj35 ], [ %reg.1_66, %Lj34 ], [ %reg.1_66, %Lj31 ], [ %tmp.6.0, %Lj29 ], [ %tmp.6.0, %Lj28 ], [ %tmp.6.0, %Lj27 ], [ %tmp.6.0, %Lj26 ], [ %tmp.6.0, %Lj25 ], [ %tmp.6.0, %Lj22 ], [ %tmp.6.0, %Lj20 ]
%reg.1_116 = landingpad %"typ.PROGRAM.$llvmstruct$d00000004i32"
catch i8* null
%exception_gep = getelementptr { i8*, i32, [4 x i32], i8*, i8*, [5 x i8*] }, { i8*, i32, [4 x i32], i8*, i8*, [5 x i8*] }* %fn_context, i64 0, i32 2, i64 0
%exn_val = load volatile i32, i32* %exception_gep, align 4
%exn_selector_gep = getelementptr { i8*, i32, [4 x i32], i8*, i8*, [5 x i8*] }, { i8*, i32, [4 x i32], i8*, i8*, [5 x i8*] }* %fn_context, i64 0, i32 2, i64 1
%exn_selector_val = load volatile i32, i32* %exn_selector_gep, align 4
br label %Lj13
; label where our setjmp branches to
Lj13: ; preds = %0, %Lj15
%tmp.6.2 = phi i32 [ 0, %0 ], [ %tmp.6.1.reg2mem.0, %Lj15 ]
Additionally, if you just run that pass in opt in addition to -O1 (-sjljehprepare -O1), then calling llc on the result will fail with an assert:
Assertion failed: (MI.isEHLabel() && "expected EH_LABEL"), function EmitSjLjDispatchBlock, file /Data/imacdev/llvm/lib/Target/X86/X86ISelLowering.cpp, line 25273.
That's with trunk@290046; with 3.9 I get errors about invalid relocation calculations instead. So it seems like this pass cannot be used in isolation.
I've posted the full unoptimized code for the test module at target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3 - Pastebin.com (although to run it after compiling, you'd need more).
Jonas