Skip to content
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

Clang MIPS: float register constraints for inline asm deviate from gcc #64241

Closed
shravanrn opened this issue Jul 30, 2023 · 8 comments · Fixed by #79116
Closed

Clang MIPS: float register constraints for inline asm deviate from gcc #64241

shravanrn opened this issue Jul 30, 2023 · 8 comments · Fixed by #79116

Comments

@shravanrn
Copy link

shravanrn commented Jul 30, 2023

clang and gcc seem to have different behavior of floating point constraints for inline asm targetting MIPS. Consider this simple example

// gcc compiles this but clang does not
void read_float(float* p) {
    float result = *p;
    __asm__("" ::"r"(result));
}

The following code compiles fine on gcc when targeting MIPS, but clang gives a compile error couldn't allocate input reg for constraint 'r'

Clang requires the register constraint here to be "f" not "r". However applying an "f" constraint, causes gcc to fail compilation with the error error: impossible constraint in 'asm' while clang compiles the code fine.

// clang compiles this but gcc does not
void read_float(float* p) {
    float result = *p;
    __asm__("" ::"f"(result));
}

Here is a simple demo of the issue: https://godbolt.org/z/WGWxd3ejo
Test with "mips gcc 13.1.0" and "mips clang 16.0.0"

(This bug was discovered as part of the wasm2c project WebAssembly/wabt#2266)

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 30, 2023

@llvm/issue-subscribers-backend-mips

@pinskia
Copy link

pinskia commented Nov 5, 2023

Note the f constraint works with GCC if enable hard float (that is -mhard-float option). The godbolt's mips gcc defaults to soft-float (--with-float=soft on the configure line).

@brad0
Copy link
Contributor

brad0 commented Jan 17, 2024

cc @wzssyqa @yingopq

@wzssyqa
Copy link
Contributor

wzssyqa commented Jan 21, 2024

Should we consider it as a bug of gcc or clang ;)
I think that we should support "f" for soft float, and map it to "r".

@pinskia
Copy link

pinskia commented Jan 21, 2024

Should we consider it as a bug of gcc or clang ;) I think that we should support "f" for soft float, and map it to "r".
It is not a bug in either, just the default configure options for GCC vs clang on godbolt. GCC defaults to soft-float while clang defaults to hard float.

Note with -msoft-float on clang, it is rejected too. Though there is an internal compiler error and that is definitely a bug.

@wzssyqa
Copy link
Contributor

wzssyqa commented Jan 23, 2024

Ohh, I know. Let me have a try.

wzssyqa added a commit to wzssyqa/llvm-project that referenced this issue Jan 23, 2024
Currently, clang accpets contraint f for softfloat, then
LLVM meet an internal error.

See: llvm#64241
@wzssyqa
Copy link
Contributor

wzssyqa commented Jan 23, 2024

This PR fixes half of this problem: no-ICE if f is used for soft-float.

We also need to support r for soft-float.

wzssyqa added a commit to wzssyqa/llvm-project that referenced this issue Feb 2, 2024
This include 2 fixes:
	1. Disallow 'f' for softfloat.
	2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: llvm#64241
@wzssyqa
Copy link
Contributor

wzssyqa commented Feb 2, 2024

#79116

can solve the whole of problem now.

wzssyqa added a commit to wzssyqa/llvm-project that referenced this issue Feb 2, 2024
This include 2 fixes:
	1. Disallow 'f' for softfloat.
	2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: llvm#64241
wzssyqa added a commit to wzssyqa/llvm-project that referenced this issue Feb 3, 2024
This include 2 fixes:
	1. Disallow 'f' for softfloat.
	2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: llvm#64241
wzssyqa added a commit to wzssyqa/llvm-project that referenced this issue Feb 21, 2024
This include 2 fixes:
	1. Disallow 'f' for softfloat.
	2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: llvm#64241
wzssyqa added a commit to wzssyqa/llvm-project that referenced this issue Feb 22, 2024
This include 2 fixes:
	1. Disallow 'f' for softfloat.
	2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: llvm#64241
MaskRay pushed a commit to wzssyqa/llvm-project that referenced this issue Feb 27, 2024
This include 2 fixes:
	1. Disallow 'f' for softfloat.
	2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then
LLVM meet an internal error.

'r' is rejected by LLVM by:
  couldn't allocate input reg for constraint 'r'

Fixes: llvm#64241
MaskRay added a commit that referenced this issue Feb 27, 2024
This include 2 fixes:
        1. Disallow 'f' for softfloat.
        2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then LLVM meets an internal error.

'r' is rejected by LLVM by: couldn't allocate input reg for constraint
'r'.

Fixes: #64241, #63632

---------

Co-authored-by: Fangrui Song <i@maskray.me>
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Feb 27, 2024
This include 2 fixes:
        1. Disallow 'f' for softfloat.
        2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then LLVM meets an internal error.

'r' is rejected by LLVM by: couldn't allocate input reg for constraint
'r'.

Fixes: llvm#64241, llvm#63632

---------

Co-authored-by: Fangrui Song <i@maskray.me>
(cherry picked from commit c88beb4)
llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Feb 27, 2024
This include 2 fixes:
        1. Disallow 'f' for softfloat.
        2. Allow 'r' for softfloat.

Currently, 'f' is accpeted by clang, then LLVM meets an internal error.

'r' is rejected by LLVM by: couldn't allocate input reg for constraint
'r'.

Fixes: llvm#64241, llvm#63632

---------

Co-authored-by: Fangrui Song <i@maskray.me>
(cherry picked from commit c88beb4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants