LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 30426 - x86_64 with SSE2 disabled: Assertion failed: (Reg >= X86::FP0 && Reg <= X86::FP6 && "Expected FP register!"), function getFPReg
Summary: x86_64 with SSE2 disabled: Assertion failed: (Reg >= X86::FP0 && Reg <= X86::...
Status: CONFIRMED
Alias: None
Product: libraries
Classification: Unclassified
Component: Backend: X86 (show other bugs)
Version: trunk
Hardware: PC All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
: 37067 48803 51468 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-09-17 06:44 PDT by Dimitry Andric
Modified: 2021-11-01 17:31 PDT (History)
15 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dimitry Andric 2016-09-17 06:44:05 PDT
This is a rather strange one.  I got a test case via FreeBSD bug 212703 [1], where somebody encountered a clang 3.4.1 segfault, compiling some sample from openMVG [2].

This segfault is actually the assertion "(Reg >= X86::FP0 && Reg <= X86::FP6 && "Expected FP register!"), function getFPReg", and it even reproduces with trunk r281149.

For some reason, the build process targets x86_64, but then turns off SSE2, and this is the key to getting the assertion.  The test case is extremely minimal, and optimization isn't even required:

// compile with: clang -cc1 -triple x86_64 -S -target-feature -sse2 testcase.cpp
void fn1(double);
int main() { fn1(4.); }

As far as I know, disabling SSE2 also disables all the higher forms of SSE, so I think it just can't find any x87 FP register at all, in this case?

[1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=212703
[2] https://github.com/openMVG/openMVG
Comment 1 Simon Pilgrim 2016-09-17 08:04:39 PDT
Duplicate of [Bug #10498]?
Comment 2 Michael Kuperstein 2016-09-17 19:07:01 PDT
Is x86-64 without sse2 a configuration we try to support?
As far as I know, x86-64 implies sse2 (and the x86-64 System V ABI certainly does).
Comment 3 Dimitry Andric 2016-09-17 19:15:19 PDT
(In reply to comment #2)
> Is x86-64 without sse2 a configuration we try to support?

Maybe not, though it would be better to simply refuse the -mno-sse and -mno-sse2 options on the command line then.


> As far as I know, x86-64 implies sse2 (and the x86-64 System V ABI certainly
> does).

Could it just fall back to x87 floating point?  Maybe that was the expectation in openMVG...  Though reading its CMake files, it appears that it may simply fail to detect SSE2 properly, and then tries to disable it.
Comment 4 Dimitry Andric 2016-09-17 19:17:37 PDT
(In reply to comment #1)
> Duplicate of [Bug #10498]?

Yeah, it looks quite a bit like it; maybe the call to fn1() uses SSE registers, while the function itself expects x87 FP registers, or something like that.
Comment 5 Michael Kuperstein 2016-09-18 13:20:36 PDT
(In reply to comment #3)
> (In reply to comment #2)
> > Is x86-64 without sse2 a configuration we try to support?
> 
> Maybe not, though it would be better to simply refuse the -mno-sse and
> -mno-sse2 options on the command line then.

That's what I meant.

> 
> > As far as I know, x86-64 implies sse2 (and the x86-64 System V ABI certainly
> > does).
> 
> Could it just fall back to x87 floating point?

Not really. It could for computation, but not for the ABI - if the calling convention mandates returning in xmm0, there's no real fallback that makes sense.

GCC appears to actually make this distinction, so it will only refuse to compile when it sees an actual ABI problem. So, say:

float square(float f) {
  return f * f;
}

When built with GCC for x86-64 with -mno-sse, errors with: "SSE register return with SSE disabled". GCC is, however, perfectly willing to compile it with only SSE2 disabled.
Comment 6 Reid Kleckner 2016-09-22 01:26:13 PDT
(In reply to comment #5)
> (In reply to comment #3)
> > (In reply to comment #2)
> > > Is x86-64 without sse2 a configuration we try to support?
> > 
> > Maybe not, though it would be better to simply refuse the -mno-sse and
> > -mno-sse2 options on the command line then.
> 
> That's what I meant.

Let's do that. Users seem to keep bumping into impossibilities in x86_64 -mno-sse[2], and then clang asks them to file a bug report.
Comment 7 Francis Visoiu Mistrih 2016-12-26 04:47:15 PST
Maybe this can help: https://reviews.llvm.org/D27522.
Comment 8 Reid Kleckner 2017-05-12 09:03:00 PDT
(In reply to Francis Visoiu Mistrih from comment #7)
> Maybe this can help: https://reviews.llvm.org/D27522.

I landed a modified version of this patch. However, it's still possible to hit this assertion, so the issue is not fixed.
Comment 9 Dimitry Andric 2017-05-18 15:52:03 PDT
(In reply to Reid Kleckner from comment #8)
> (In reply to Francis Visoiu Mistrih from comment #7)
> > Maybe this can help: https://reviews.llvm.org/D27522.
> 
> I landed a modified version of this patch. However, it's still possible to
> hit this assertion, so the issue is not fixed.

Reid, any ideas what kind of situation can still trigger that?
Comment 10 Reid Kleckner 2017-05-18 16:19:26 PDT
(In reply to Dimitry Andric from comment #9)
> (In reply to Reid Kleckner from comment #8)
> > (In reply to Francis Visoiu Mistrih from comment #7)
> > > Maybe this can help: https://reviews.llvm.org/D27522.
> > 
> > I landed a modified version of this patch. However, it's still possible to
> > hit this assertion, so the issue is not fixed.
> 
> Reid, any ideas what kind of situation can still trigger that?

This test case was part of r302835, the revision that I forgot to note:

+void take_double(double);
+void pass_double(void) {
+  // FIXME: Still asserts.
+  //take_double(1.5);
+}
Comment 11 Tom Stellard 2019-02-12 13:24:09 PST
(In reply to Dimitry Andric from comment #9)
> (In reply to Reid Kleckner from comment #8)
> > (In reply to Francis Visoiu Mistrih from comment #7)
> > > Maybe this can help: https://reviews.llvm.org/D27522.
> > 
> > I landed a modified version of this patch. However, it's still possible to
> > hit this assertion, so the issue is not fixed.
> 
> Reid, any ideas what kind of situation can still trigger that?

The test case attached to https://bugs.llvm.org/show_bug.cgi?id=10498 still hits this assertion with trunk (r353878).
Comment 12 Dimitry Andric 2020-05-23 08:11:42 PDT
*** Bug 37067 has been marked as a duplicate of this bug. ***
Comment 13 Dimitry Andric 2021-01-19 12:14:32 PST
*** Bug 48803 has been marked as a duplicate of this bug. ***
Comment 14 Dimitry Andric 2021-08-13 04:10:20 PDT
*** Bug 51468 has been marked as a duplicate of this bug. ***
Comment 15 Douglas Yung 2021-11-01 17:31:48 PDT
We recently hit this assertion when investigating an issue internally when compiling with following code with -mno-sse2:

void foo(...) { foo(4.0); }