-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Support the inline asm 'a' constraint on PowerPC #141604
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
Open
kamaub
wants to merge
5
commits into
llvm:main
Choose a base branch
from
kamaub:kamaub/inlineAsmAConstraint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b4e809b
[WIP] Support the inline asm 'a' constraint on PowerPC
kamaub 7bf36cb
Removing the backend type promotion test case file
kamaub 8bff2c8
Applying git clang format NFC
kamaub c63b5b2
Addressing Review comments
kamaub fa8ebcf
Apply suggestion from @kamaub
kamaub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
// RUN: %clang_cc1 -emit-llvm-only -triple powerpc64-ibm-aix-xcoff -verify %s | ||
// RUN: %clang_cc1 -emit-llvm-only -triple powerpc-ibm-aix-xcoff -verify %s | ||
// This test case exist to test marking the 'a' inline assembly constraint as | ||
// unsupported because powerpc previously marked it as supported. | ||
int foo(int arg){ | ||
asm goto ("bc 12,2,%l[TEST_LABEL]" : : "a"(&&TEST_LABEL) : : TEST_LABEL); //expected-error {{invalid input constraint 'a' in asm}} | ||
// This test file validates that we diagnose inline assembly constraint error | ||
// in the clang front-end as expected. | ||
|
||
int labelConstraintError(int arg){ | ||
asm goto ("bc 12,2,%l[TEST_LABEL]" : : "s"(&&TEST_LABEL) : : TEST_LABEL); //expected-error {{invalid input constraint 's' in asm}} | ||
return 0; | ||
TEST_LABEL: return arg + 1; | ||
} | ||
|
||
char wrongAddrConstraint(char* result) { | ||
asm ("stb %1,%0" : "a"(result) : "r"('E') :); //expected-error {{invalid output constraint 'a' in asm}} | ||
return *result; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// RUN: %clang_cc1 -emit-llvm -triple powerpc64-ibm-aix-xcoff \ | ||
// RUN: %s -o - | FileCheck %s | ||
// RUN: %clang_cc1 -emit-llvm -triple powerpc-ibm-aix-xcoff \ | ||
// RUN: %s -o - | FileCheck %s | ||
// This test file checks that we represent common C inline assembly | ||
// PowerPC load address mode operations accureately in the platform | ||
// agnostic LLVM IR. | ||
|
||
kamaub marked this conversation as resolved.
Show resolved
Hide resolved
kamaub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
char loadAddressAConstrained(char* ptr) { | ||
// CHECK-LABEL: define{{.*}} i8 @loadAddressAConstrained(ptr noundef %ptr) | ||
// CHECK: %1 = call ptr asm "addi $0,$1, 0", "=r,a"(ptr %0) | ||
char* result; | ||
asm ("addi %0,%1, 0" : "=r"(result) : "a"(ptr) :); | ||
return *result; | ||
} | ||
|
||
char loadAddressZyConstrained(char* ptr) { | ||
// CHECK-LABEL: define{{.*}} i8 @loadAddressZyConstrained(ptr noundef %ptr) | ||
// CHECK: %1 = call ptr asm "add $0,${1:y}", "=r,*Z"(ptr elementtype(i8) %0) | ||
char* result; | ||
asm ("add %0,%y1" : "=r"(result) : "Z"(*ptr) :); | ||
return *result; | ||
} | ||
|
||
char xFormRegImmLoadAConstrained(char* ptr) { | ||
// CHECK-LABEL: define{{.*}} i8 @xFormRegImmLoadAConstrained(ptr noundef %ptr) | ||
// CHECK: %1 = call ptr asm "addi $0,$1,$2", "=r,a,I"(ptr %0, i32 10000) | ||
char* result; | ||
asm ("addi %0,%1,%2" : "=r"(result) : "a"(ptr), "I"(10000) :); | ||
return *result; | ||
} | ||
|
||
char loadIndirectAddressZConstrained(char* ptr) { | ||
// CHECK-LABEL: define{{.*}} i8 @loadIndirectAddressZConstrained(ptr noundef %ptr) | ||
// CHECK: %1 = call ptr asm "ld $0,$1", "=r,*Z"(ptr elementtype(i8) %arrayidx) | ||
char* result; | ||
asm ("ld %0,%1" : "=r"(result) : "Z"(ptr[100]) :); | ||
return *result; | ||
} | ||
|
||
char loadIndirectAddressAConstrained(char** ptr, unsigned index) { | ||
// CHECK-LABEL: define{{.*}} i8 @loadIndirectAddressAConstrained(ptr noundef %ptr, i32 noundef{{[ zeroext]*}} %index) | ||
// CHECK: %2 = call ptr asm "ldx $0,$1,$2", "=r,a,r"(ptr %0, i32 %1) | ||
char* result; | ||
asm ("ldx %0,%1,%2" : "=r"(result) : "a"(ptr), "r"(index) :); | ||
return *result; | ||
} | ||
|
||
char dFormLoadZConstrained(char* ptr) { | ||
// CHECK-LABEL: define{{.*}} i8 @dFormLoadZConstrained(ptr noundef %ptr) | ||
// CHECK: %1 = call i8 asm "lbz $0,$1", "=r,*Z"(ptr elementtype(i8) %arrayidx) | ||
char result; | ||
asm ("lbz %0,%1" : "=r"(result) : "Z"(ptr[8]) :); | ||
return result; | ||
} | ||
|
||
char xFormRegRegLoadZyConstrained(char* ptr, unsigned index) { | ||
// CHECK-LABEL: define{{.*}} i8 @xFormRegRegLoadZyConstrained(ptr noundef %ptr, i32 noundef{{[ zeroext]*}} %index) | ||
// CHECK: %2 = call i8 asm "lbzx $0, ${1:y}", "=r,*Z"(ptr elementtype(i8) %arrayidx) | ||
char result; | ||
asm("lbzx %0, %y1" : "=r"(result) : "Z"(ptr[index]) :); | ||
return result; | ||
} | ||
|
||
char xFormRegRegLoadAConstrained(char* ptr, unsigned index) { | ||
// CHECK-LABEL: define{{.*}} i8 @xFormRegRegLoadAConstrained(ptr noundef %ptr, i32 noundef{{[ zeroext]*}} %index) | ||
// CHECK: %2 = call i8 asm "lbzx $0,$1,$2", "=r,a,r"(ptr %0, i32 %1) | ||
char result; | ||
asm ("lbzx %0,%1,%2" : "=r"(result) : "a"(ptr), "r"(index) :); | ||
return result; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc -verify-machineinstrs < %s -mcpu=pwr8 \ | ||
; RUN: -mtriple=powerpc64-ibm-aix-xcoff | FileCheck %s | ||
; RUN: llc -verify-machineinstrs < %s -mcpu=pwr8 \ | ||
; RUN: -mtriple=powerpc-ibm-aix-xcoff | FileCheck %s | ||
|
||
define signext i8 @loadAddressAConstrained(ptr %ptr) { | ||
; CHECK-LABEL: loadAddressAConstrained: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: #APP | ||
; CHECK-NEXT: addi 3, 3, 0 | ||
; CHECK-NEXT: #NO_APP | ||
; CHECK-NEXT: lbz 3, 0(3) | ||
; CHECK-NEXT: extsb 3, 3 | ||
; CHECK-NEXT: blr | ||
entry: | ||
%0 = tail call ptr asm "addi $0,$1, 0", "=r,a"(ptr %ptr) | ||
%1 = load i8, ptr %0, align 1 | ||
ret i8 %1 | ||
} | ||
|
||
define signext i8 @xFormRegImmLoadAConstrained(ptr %ptr) { | ||
; CHECK-LABEL: xFormRegImmLoadAConstrained: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: #APP | ||
; CHECK-NEXT: addi 3, 3, 10000 | ||
; CHECK-NEXT: #NO_APP | ||
; CHECK-NEXT: lbz 3, 0(3) | ||
; CHECK-NEXT: extsb 3, 3 | ||
; CHECK-NEXT: blr | ||
entry: | ||
%0 = tail call ptr asm "addi $0,$1,$2", "=r,a,I"(ptr %ptr, i32 10000) | ||
%1 = load i8, ptr %0, align 1 | ||
ret i8 %1 | ||
} | ||
|
||
define signext i8 @loadIndirectAddressZConstrained(ptr %ptr) { | ||
; CHECK-LABEL: loadIndirectAddressZConstrained: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: addi 3, 3, 800 | ||
; CHECK-NEXT: #APP | ||
; CHECK-NEXT: ld 3, 0(3) | ||
; CHECK-NEXT: #NO_APP | ||
; CHECK-NEXT: lbz 3, 0(3) | ||
; CHECK-NEXT: extsb 3, 3 | ||
; CHECK-NEXT: blr | ||
entry: | ||
%arrayidx = getelementptr inbounds nuw i8, ptr %ptr, i64 800 | ||
%0 = tail call ptr asm "ld $0,$1", "=r,*Z"(ptr nonnull elementtype(ptr) %arrayidx) | ||
%1 = load i8, ptr %0, align 1 | ||
ret i8 %1 | ||
} | ||
|
||
define signext i8 @loadIndirectAddressAConstrained(ptr %ptr, i32 zeroext %index) { | ||
; CHECK-LABEL: loadIndirectAddressAConstrained: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: #APP | ||
; CHECK-NEXT: ldx 3, 3, 4 | ||
; CHECK-NEXT: #NO_APP | ||
; CHECK-NEXT: lbz 3, 0(3) | ||
; CHECK-NEXT: extsb 3, 3 | ||
; CHECK-NEXT: blr | ||
entry: | ||
%0 = tail call ptr asm "ldx $0,$1,$2", "=r,a,r"(ptr %ptr, i32 zeroext %index) | ||
%1 = load i8, ptr %0, align 1 | ||
ret i8 %1 | ||
} | ||
|
||
define signext i8 @dFormLoadZConstrained(ptr %ptr) { | ||
; CHECK-LABEL: dFormLoadZConstrained: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: addi 3, 3, 8 | ||
; CHECK-NEXT: #APP | ||
; CHECK-NEXT: lbz 3, 0(3) | ||
; CHECK-NEXT: #NO_APP | ||
; CHECK-NEXT: extsb 3, 3 | ||
; CHECK-NEXT: blr | ||
entry: | ||
%arrayidx = getelementptr inbounds nuw i8, ptr %ptr, i64 8 | ||
%0 = tail call i8 asm "lbz $0,$1", "=r,*Z"(ptr nonnull elementtype(i8) %arrayidx) | ||
ret i8 %0 | ||
} | ||
|
||
define signext i8 @xFormRegRegLoadZyConstrained(ptr %ptr, i32 zeroext %index) { | ||
; CHECK-LABEL: xFormRegRegLoadZyConstrained: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: add 3, 3, 4 | ||
; CHECK-NEXT: #APP | ||
; CHECK-NEXT: lbzx 3, 0, 3 | ||
; CHECK-NEXT: #NO_APP | ||
; CHECK-NEXT: extsb 3, 3 | ||
; CHECK-NEXT: blr | ||
entry: | ||
%idxprom = zext i32 %index to i64 | ||
%arrayidx = getelementptr inbounds nuw i8, ptr %ptr, i64 %idxprom | ||
%0 = tail call i8 asm "lbzx $0, ${1:y}", "=r,*Z"(ptr elementtype(i8) %arrayidx) | ||
ret i8 %0 | ||
} | ||
|
||
define signext i8 @xFormRegRegLoadAConstrained(ptr %ptr, i32 zeroext %index) { | ||
; CHECK-LABEL: xFormRegRegLoadAConstrained: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: #APP | ||
; CHECK-NEXT: lbzx 3, 3, 4 | ||
; CHECK-NEXT: #NO_APP | ||
; CHECK-NEXT: extsb 3, 3 | ||
; CHECK-NEXT: blr | ||
entry: | ||
%0 = tail call i8 asm "lbzx $0,$1,$2", "=r,a,r"(ptr %ptr, i32 %index) | ||
ret i8 %0 | ||
} | ||
|
||
define i8 @implicitRegImmToRegRegConversion(ptr readnone %ptr, i32 zeroext %index) { | ||
; CHECK-LABEL: implicitRegImmToRegRegConversion: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: add 3, 3, 4 | ||
; CHECK-NEXT: #APP | ||
; CHECK-NEXT: lbzx 3, 0, 3 | ||
; CHECK-NEXT: #NO_APP | ||
; CHECK-NEXT: blr | ||
entry: | ||
%idx.ext = zext i32 %index to i64 | ||
%add.ptr = getelementptr inbounds nuw i8, ptr %ptr, i64 %idx.ext | ||
%0 = tail call i8 asm "lbzx $0, ${1:y}", "=r,a"(ptr %add.ptr) | ||
ret i8 %0 | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.