Closed edwintorok closed 14 years ago
ocamlbyterun works correctly now with -O1.
Fix committed here, the bug was a negative shiftamount created by dagcombiner, and subsequently eliminated as undefined: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090518/077932.html
valgrind gives some warning when llc is run with -debug:
==32222== Conditional jump or move depends on uninitialised value(s)
==32222== at 0x4CC1BE6: std::ostreambuf_iterator<char, std::char_traits
==32222== Use of uninitialised value of size 8
==32222== at 0x4CBB863: (within /usr/lib/libstdc++.so.6.0.12)
==32222== by 0x4CC1C12: std::ostreambuf_iterator<char, std::char_traits
Hmm, llc thinks the optimized bitcode has undefined behaviour, does it ?!
Replacing.3 0x2a69110: i64 = srl 0x2a3a4e8, 0x2a69208 With: 0x2a3a3f0: i64 = undef
Replacing.6 0x2a3a4e8: i64,ch = load 0x2a3a2f8, 0x2a39f18, 0x2a3a3f0 <0x2a2ed68:0>
Replacing.3 0x2a3a7d0: i64 = sign_extend_inreg 0x2a3a3f0, 0x2a3a6d8 With: 0x2a3a3f0: i64 = undef
Replacing.3 0x2a69300: i64 = or 0x2a3a3f0, 0x2a69cb0 With: 0x2a3a6d8: i64 = Constant <-1>
optimized.bc $ llc optimized.bc intern_rec_sw_2E_bb125: .LBB1_0: # newFuncRoot .LBB1_1: # sw.bb125 addq $2, intern_src(%rip) movq $-1, (%rdi) .LBB1_2: # sw.epilog.exitStub ret
I don't see where the -1 comes from by looking at the bitcode...
FWIW if I run the bitcode output from -instcombine through the C backend, and gcc -O3 I get: intern_rec_sw_2E_bb125: .LFB16: movq intern_src(%rip), %rdx leaq 2(%rdx), %rax movq %rax, intern_src(%rip) movsbq (%rdx),%rax movzbl 1(%rdx), %edx salq $8, %rax orq %rdx, %rax addq %rax, %rax orq $1, %rax movq %rax, (%rdi) ret
And here is what llc generates: intern_rec_sw_2E_bb125: .LBB1_0: # newFuncRoot .LBB1_1: # sw.bb125 addq $2, intern_src(%rip) movq $-1, (%rdi) .LBB1_2: # sw.epilog.exitStub ret
That $-1 looks bogus.
If I look at the asm diff:
It is kind of hard to follow, but where does the -1 constant come from?? It is certainly not in the bitcode output from instcombine.
So maybe this is a backend problem, and not an instcombine problem?
At first glance the transform is correct, but maybe I am missing something.
Extended Description
Symptom: the ocamlrun build by clang -O rejects pervasives.mli with a syntax error, the gcc built one doesn't, and neither does a 'clang' built ocamlrun: File "../stdlib/pervasives.mli", line 29, characters 0-8: Error: Syntax error
I've run bugpoint like this: bugpoint -run-jit -safe-run-llc -output=good -simplifycfg -domtree -domfrontier -mem2reg -instcombine -simplifycfg -simplify-libcalls -instcombine -jump-threading -simplifycfg -domtree -domfrontier -scalarrepl -instcombine -break-crit-edges -condprop -tailcallelim -simplifycfg -reassociate -domtree -loops -loopsimplify -domfrontier -lcssa -loop-rotate -licm -lcssa -loop-unswitch -loop-index-split -instcombine -scalar-evolution -lcssa -iv-users -indvars -loop-deletion -instcombine -memdep -gvn -memdep -memcpyopt -sccp -instcombine -break-crit-edges -condprop -domtree -memdep -dse -adce -simplifycfg -preverify -domtree -verify ocamlrun.bc -Xlinker=-lm -Xlinker=-lpthread -Xlinker=-ldl -Xlinker=-lcurses --args -- ../boot/ocamlc -g -warn-error A -nostdlib-nopervasives -c ../stdlib/pervasives.mli
And I got 2 bitcodes: bugpoint-tooptimize.bc, and bugpoint-tonotoptimize.bc. Bugpoint says -instcombine breaks the program.
Here is what instcombine does: