New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bad machine code: MBB exits via unconditional fall-through but its successor differs from its CFG successor #22277
Comments
compiles fine for me on clang version 3.6.0 (trunk 224110) (llvm/trunk 224168) Try updating and reopen if you can still reproduce. |
FWIW, this bug affects clang 3.4, 3.4.1, 3.4.2 and 3.5.0. After bisection, it seems to be fixed by r222008, but that is very hard to apply to older releases. So I guess release users are SOL for now... |
I got very similar crash report for the fontforge port [1], and this results in a crash, even with trunk r224516. Note that this only happens with assertions enabled! The resulting message is very similar, after BB dumps, it gives: *** Bad machine code: MBB exits via unconditional fall-through but its successor differs from its CFG successor! ***
*** Bad machine code: MBB exits via unconditional fall-through but its successor differs from its CFG successor! ***
*** Bad machine code: MBB exits via unconditional fall-through but its successor differs from its CFG successor! ***
*** Bad machine code: MBB exits via unconditional fall-through but its successor differs from its CFG successor! ***
*** Bad machine code: MBB exits via unconditional fall-through but its successor differs from its CFG successor! ***
*** Bad machine code: Using an undefined physical register ***
Specifically, the "FNSTSW16r %AX, %FPSW<imp-use,kill>" is precisely the same as in the Inkscape case. I think this must be some sort of bug in the (x87) floating point optimization. I will add a reduced test case after this comment. [1] http://pb2.nyi.freebsd.org/data/head-i386-#195480 -default/2014-12-15_22h55m50s/logs/errors/fontforge-20120731.b_7.log |
Test case, minimized from FontForge's splineutil2.c clang -cc1 -triple i386-unknown-linux -c -O2 fontforge-splineutil2-reduced.c Any other i386 triple is also fine, e.g. 'i386-unknown-freebsd', or even just 'i386'. Also, in contrast to the previous test case, this does not even need -target-cpu i486. |
This still crashes with trunk r225622, and clang 3.6.0. |
reduced ir: declare void @f() define i1 @SplineIsLinear(double %a, float %e) { if.then: ; preds = %0 if.end: ; preds = %if.then, %0 if.end.i: ; preds = %if.end if.then2.i: ; preds = %if.end.i if.end4.i: ; preds = %if.end.i Within16RoundingErrors.exit: ; preds = %if.end4.i, %if.then2.i, %if.end land.rhs: ; preds = %Within16RoundingErrors.exit if.then.i12: ; preds = %land.rhs if.end.i14: ; preds = %land.rhs if.end4.i20: ; preds = %if.end.i14 land.end: ; preds = %if.end4.i20, %if.end.i14, %if.then.i12, %Within16RoundingErrors.exit |
reduced further: declare void @f() define i1 @SplineIsLinear(double %a, float %e) { if.then: ; preds = %0 if.end: ; preds = %if.then, %0 if.end.i: ; preds = %if.end if.then2.i: ; preds = %if.end.i if.end4.i: ; preds = %if.end.i Within16RoundingErrors.exit: ; preds = %if.end4.i, %if.then2.i, %if.end |
Just for reference, still crashing with clang 3.7.0 release. :-( |
Still crashes with trunk r252206 (as of 2015-11-07). |
Don't consider unallocatable registers dead |
Send a patch to llvm-commits and CC somebody like Matthias Braun. |
FWIW, this patch solves the crash, in any case. |
The patch looks bogus to me: !Allocatable registers have different semsntic from reserved registers. !Allocatable registers are tracked perfectly fine by the register scavenger and should not need the change in this patch. Conversely !allocatable registers must have correct def/uses/live in annotations we should not disable machine verification for them. I looked into what is happening here, it looks like we have some invalid defs/uses of the FPSW register after register allocation. You can check this with -verify-machineinstr and see the error being present after greedy register allocation (unfortunately -verify-machineinstr is not enabled by default even in debug builds because of compiletime concerns). |
As for fixing this properly: The problem appears to be that a reload of an x87 value is inserted at a point in the program where the FPSW register is live (it lives between an UCOM and the corresponding FNSTSW to get the comparison result into a GPR register). Unfortunately the reload instruction looks like this: %vreg78 = LD_Fp032 %FPSW<imp-def,dead> which clobbers the FPSW value. The register allocator is not prepared for spill and reload instructions clobbering unrelated registers AFAIK. From reading the intel manual it seems that fld does indeed clobber the C0,C2,C3 bits set by fucom. The only proper fix I see right now, would be to introduce a pseudo instruction for the UCOM+FNSTSW pair which expanded after register allocation so no reload can be placed between the two instructions. |
Some kind of pseudo is indeed the way to go. |
Attempting to revive this bug again. It still occurs with trunk r258168. I now also encountered it while building gmsh (see http://gmsh.info/ ), where clang dies on its periodic.cpp file, with a similar error as described earlier in this bug. Reduced C++ test case: class voroMetal3D { Compiling this with "clang -cc1 -triple i386 -emit-obj -O2 testcase.cpp" will result in |
Attempting to revive this bug again. It still occurs with trunk r258168. I now also encountered it while building gmsh (see http://gmsh.info/ ), where clang dies on its periodic.cpp file, with a similar error as described earlier in this bug. Reduced C++ test case: class voroMetal3D { Compiling this with "clang -cc1 -triple i386 -emit-obj -O2 testcase.cpp" will result in a machine code dump, followed by: *** Bad machine code: MBB exits via conditional branch/fall-through but the CFG successors don't match the actual successors! ***
*** Bad machine code: Using an undefined physical register ***
*** Bad machine code: Using an undefined physical register ***
|
Can somebody please reduce the test case in comment 17 to .ll form again? I never understand how to use bugpoint to do this. :-) |
This is how: After some manual reduction, I am left with: define void @f(double %p1, double %p2, double %p3, double %p4, i32 %p5, i8* %p6, double %p7, double %p8, double %p9) align 2 { land.lhs.true: ; preds = %entry land.lhs.true3: ; preds = %land.lhs.true15, %land.lhs.true land.lhs.true5: ; preds = %land.lhs.true3 if.then10: ; preds = %land.lhs.true5, %entry, %entry land.lhs.true13: ; preds = %entry land.lhs.true15: ; preds = %land.lhs.true13 if.end20: ; preds = %land.lhs.true13, %if.then10, %land.lhs.true5, %land.lhs.true3, %land.lhs.true, %entry |
We know what the bug is, see my previous comment. However at least for me this is low priority because: It only affects machines before i686 (it's easy to work around this with -march=i686 or similar) and the fix will probably take some time implementing and testing properly. If someone else wants to take a stab at fixing it? |
Also the error symptom here is somewhat generic, it mainly means that there is some error in the internal representation of the function, it's not necessarily the same bug. The 2nd case you posted appears to be happening for i686 as well, so there's a high chance this is a different underlying bug which should be put into an own ticket. |
Interestingly, r192635 ("Fix the ExecutionDepsFix pass to handle AVX instructions") appears to introduce the failure for the fontforge-splineutil2-reduced.c test case. E.g r192634 compiles it without complaints, r192635 results in the bad machine code dump. I'm unsure whether it really 'causes' it, or if it is just a side effect, or even a red herring. :) |
r275201 (BranchFolding: Use LivePhysReg to update live in lists) fixes this. |
I didn't see any work addressing the underlying problem (x87 reloads cannot be placed everywhere because they (possibly) clobber FPSW status flags). So this not failing anymore is probably luck... |
And indeed, the fontforge-splineutil2-reduced.c testcase still fails with trunk r278432: ~/obj/llvm-trunk-278432/bin/clang -cc1 -triple i386 -S -target-cpu i686 -O2 -mllvm -verify-machineinstrs=1 fontforge-splineutil2-reduced.c
So this problem is definitely not fixed. |
This bug was finally fixed (after a few years! :) with https://reviews.llvm.org/rL353536 ("[X86] Remove isReMaterializable from X87 floating point constant loads and constant pool loads"). |
mentioned in issue #26765 |
mentioned in issue #27855 |
Extended Description
I received a report from the maintainer of the FreeBSD inkscape port, about clang giving a lot of "Bad machine code" messages when compiling a certain source file in this program:
http://beefy1.isc.freebsd.org/data/head-i386-default/2014-12-12_10h09m09s/logs/inkscape-0.48.5_1.log
The errors are as follows:
*** Bad machine code: MBB exits via conditional branch/fall-through but the CFG successors don't match the actual successors! ***
*** Bad machine code: MBB exits via unconditional fall-through but its successor differs from its CFG successor! ***
*** Bad machine code: MBB exits via unconditional fall-through but its successor differs from its CFG successor! ***
*** Bad machine code: MBB exits via conditional branch/fall-through but the CFG successors don't match the actual successors! ***
*** Bad machine code: Using an undefined physical register ***
This crash occurs both with clang 3.4.1 (current in FreeBSD 9.x through 11.x), and 3.5.0 (which is coming up in FreeBSD 11.x). When I tried with clang trunk r223525, it spun at 100% CPU, until I killed it after 10 minutes or so (but it didn't use a lot of memory).
I have reduced the test case to the attached file, which can be compiled with:
clang -cc1 -triple i386-unknown-linux -S -mrelocation-model static -target-cpu i486 -O2 inkscape-geom-reduced.cpp
resulting in:
*** Bad machine code: MBB exits via unconditional fall-through but its successor differs from its CFG successor! ***
*** Bad machine code: MBB exits via conditional branch/fall-through but the CFG successors don't match the actual successors! ***
*** Bad machine code: Using an undefined physical register ***
fatal error: error in backend: Found 3 machine code errors.
These errors show for -target-cpu values of i486, i586 and i686, but as far as I can determine, they disappear when using pentium2 or 'higher'.
The text was updated successfully, but these errors were encountered: