Skip to content

[CodeGen] Allow mixed scalar type constraints for inline asm #65465

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

Merged
merged 2 commits into from
Aug 29, 2024

Conversation

dfszabo
Copy link
Contributor

@dfszabo dfszabo commented Sep 6, 2023

GCC supports code like "asm volatile ("" : "=r" (i) : "0" (f))" where i is integer type and f is floating point type. Currently this code produces an error with Clang. The change allows mixed scalar types between input and output constraints.

@dfszabo dfszabo requested review from a team as code owners September 6, 2023 11:11
@cor3ntin cor3ntin added llvm:SelectionDAG SelectionDAGISel as well and removed llvm:SelectionDAGP labels Sep 9, 2023
@RKSimon
Copy link
Collaborator

RKSimon commented Sep 13, 2023

Are there existing bug issues associated with this?

@dfszabo
Copy link
Contributor Author

dfszabo commented Sep 13, 2023

Are there existing bug issues associated with this?

I don't know. Found this issue in our downstream target.

@@ -0,0 +1,8 @@
// RUN: %clang_cc1 %s -emit-llvm -o /dev/null

unsigned test(float f)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What IR does this generate?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is using -emit-llvm, but the patch is in SelectionDAG. SelectionDAG doesn't run with -emit-llvm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. You are right, indeed the test was pointless, the problem is with CodeGen. Updated the issue accordingly.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Sep 18, 2023
@dfszabo dfszabo force-pushed the main-inline-asm-fix-fp-int-move branch from 5d403b7 to 22c95d7 Compare September 18, 2023 15:44
@dfszabo dfszabo force-pushed the main-inline-asm-fix-fp-int-move branch from 22c95d7 to 04f13a6 Compare September 18, 2023 15:48
@dfszabo dfszabo changed the title [Clang] Allow mixed scalar type constraints for inline asm [CodeGen] Allow mixed scalar type constraints for inline asm Sep 18, 2023
@dfszabo dfszabo force-pushed the main-inline-asm-fix-fp-int-move branch from 04f13a6 to ea6ac87 Compare September 18, 2023 16:05
@dfszabo dfszabo requested a review from topperc September 20, 2023 12:54
@dfszabo
Copy link
Contributor Author

dfszabo commented Sep 26, 2023

Ping

1 similar comment
@dfszabo
Copy link
Contributor Author

dfszabo commented Nov 10, 2023

Ping

%i = alloca i32, align 4
store float %f, ptr %f.addr, align 4
%0 = load float, ptr %f.addr, align 4
%1 = call i32 asm sideeffect "", "=r,0,~{dirflag},~{fpsr},~{flags}"(float %0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use named values in tests

store i32 %1, ptr %i, align 4
%2 = load i32, ptr %i, align 4
ret i32 %2
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also try the same, except with a mixed pointer and int/float? Also some vector cases?

@dfszabo dfszabo force-pushed the main-inline-asm-fix-fp-int-move branch from eb8afd2 to 0a3516b Compare February 29, 2024 19:27
@dfszabo dfszabo requested a review from arsenm May 7, 2024 13:21
%f.addr = alloca float*, align 4
%i = alloca i32, align 4
store float* %f, ptr %f.addr, align 4
%load_f = load float*, ptr %f.addr, align 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test needs to be updated to use opaque pointers. Also you don't need all of this intermediate alloca stuff, you can simplify the incoming values and uses

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test needs cleanup

; return i;
; }


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some comments explaining what this is showing

GCC supports code like "asm volatile ("" : "=r" (i) : "0" (f))" where i is integer type and f is floating point type. Currently this code produces an error with Clang. The change allows mixed scalar types between input and output constraints.
@dfszabo dfszabo force-pushed the main-inline-asm-fix-fp-int-move branch from 52423a1 to 52e62c6 Compare May 21, 2024 13:33
@dfszabo dfszabo requested a review from arsenm May 21, 2024 18:58
@arsenm arsenm requested review from RKSimon and removed request for a team May 21, 2024 19:05
; CHECK-NEXT: # kill: def $eax killed $eax killed $rax
; CHECK-NEXT: retq
entry:
%asm_call = call i32 asm sideeffect "", "=r,0,~{dirflag},~{fpsr},~{flags}"(ptr %f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really allowed to have the mismatched sizes, pointer 64 with i32? Should that be an x86-only thing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about double + i32? Or i16 + float?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. GCC seems to accept whatever garbage you give it.

@dfszabo dfszabo requested a review from arsenm May 22, 2024 09:11
; CHECK-NEXT: # kill: def $eax killed $eax killed $rax
; CHECK-NEXT: retq
entry:
%asm_call = call i32 asm sideeffect "", "=r,0,~{dirflag},~{fpsr},~{flags}"(ptr %f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh. GCC seems to accept whatever garbage you give it.

@dfszabo
Copy link
Contributor Author

dfszabo commented Aug 29, 2024

Well if approved, then can someone merge it?

@arsenm arsenm merged commit e9eaf19 into llvm:main Aug 29, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang Clang issues not falling into any other category llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants