forked from rust-lang/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 39
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
[SOL] Remove neg
and change the semantics of sub
#73
Merged
nvjle
merged 4 commits into
anza-xyz:solana-rustc/16.0-2023-06-05
from
LucasSte:neg-sub
Dec 16, 2023
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
This file contains 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 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 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,59 @@ | ||
; RUN: llc < %s -march=sbf -mattr=+alu32 | FileCheck %s | ||
; | ||
; Source: | ||
; int test_func_64(long * vec, long idx) { | ||
; vec[idx] = -idx; | ||
; return idx; | ||
; } | ||
; | ||
; int test_func_32(int * vec, int idx) { | ||
; vec[idx] = -idx; | ||
; return idx; | ||
; } | ||
; | ||
; Compilation flag: | ||
; clang -S -emit-llvm test.c | ||
|
||
; Function Attrs: noinline nounwind optnone ssp uwtable(sync) | ||
define i32 @test_func_32(ptr noundef %vec, i32 noundef %idx) #0 { | ||
; CHECK-LABEL: test_func_32: | ||
; CHECK: stxw [r10 - 12], w2 | ||
; CHECK: sub32 w2, 0 | ||
; CHECK: stxw [r1 + 0], w2 | ||
entry: | ||
%vec.addr = alloca ptr, align 8 | ||
%idx.addr = alloca i32, align 4 | ||
store ptr %vec, ptr %vec.addr, align 8 | ||
store i32 %idx, ptr %idx.addr, align 4 | ||
%0 = load i32, ptr %idx.addr, align 4 | ||
%sub = sub nsw i32 0, %0 | ||
%1 = load ptr, ptr %vec.addr, align 8 | ||
%2 = load i32, ptr %idx.addr, align 4 | ||
%idxprom = sext i32 %2 to i64 | ||
%arrayidx = getelementptr inbounds i32, ptr %1, i64 %idxprom | ||
store i32 %sub, ptr %arrayidx, align 4 | ||
%3 = load i32, ptr %idx.addr, align 4 | ||
ret i32 %3 | ||
} | ||
|
||
; Function Attrs: noinline nounwind optnone ssp uwtable(sync) | ||
define i32 @test_func_64(ptr noundef %vec, i64 noundef %idx) #0 { | ||
entry: | ||
; CHECK-LABEL: test_func_64: | ||
; CHECK: stxdw [r10 - 16], r2 | ||
; CHECK: sub64 r2, 0 | ||
; CHECK: stxdw [r1 + 0], r2 | ||
%vec.addr = alloca ptr, align 8 | ||
%idx.addr = alloca i64, align 8 | ||
store ptr %vec, ptr %vec.addr, align 8 | ||
store i64 %idx, ptr %idx.addr, align 8 | ||
%0 = load i64, ptr %idx.addr, align 8 | ||
%sub = sub nsw i64 0, %0 | ||
%1 = load ptr, ptr %vec.addr, align 8 | ||
%2 = load i64, ptr %idx.addr, align 8 | ||
%arrayidx = getelementptr inbounds i64, ptr %1, i64 %2 | ||
store i64 %sub, ptr %arrayidx, align 8 | ||
%3 = load i64, ptr %idx.addr, align 8 | ||
%conv = trunc i64 %3 to i32 | ||
ret i32 %conv | ||
} |
This file contains 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,82 @@ | ||
; RUN: llc < %s -march=sbf -mattr=+alu32 | FileCheck %s | ||
; | ||
; Source: | ||
; void test_func_64(long * vec) { | ||
; vec[0] = 50 - vec[0]; | ||
; vec[1] = vec[3] - vec[2]; | ||
; } | ||
; | ||
; void test_func_32(int * vec) { | ||
; vec[0] = 50 - vec[0]; | ||
; vec[1] = vec[3] - vec[2]; | ||
; } | ||
; | ||
; Compilation flag: | ||
; clang -S -emit-llvm test.c | ||
|
||
|
||
; Function Attrs: noinline nounwind optnone ssp uwtable(sync) | ||
define void @test_func_64(ptr noundef %vec) #0 { | ||
LucasSte marked this conversation as resolved.
Show resolved
Hide resolved
|
||
entry: | ||
; CHECK-LABEL: test_func_64: | ||
%vec.addr = alloca ptr, align 8 | ||
store ptr %vec, ptr %vec.addr, align 8 | ||
%0 = load ptr, ptr %vec.addr, align 8 | ||
%arrayidx = getelementptr inbounds i64, ptr %0, i64 0 | ||
%1 = load i64, ptr %arrayidx, align 8 | ||
%sub = sub nsw i64 50, %1 | ||
; CHECK: ldxdw r2, [r1 + 0] | ||
; CHECK: sub64 r2, 50 | ||
; CHECK: stxdw [r1 + 0], r2 | ||
%2 = load ptr, ptr %vec.addr, align 8 | ||
%arrayidx1 = getelementptr inbounds i64, ptr %2, i64 0 | ||
store i64 %sub, ptr %arrayidx1, align 8 | ||
%3 = load ptr, ptr %vec.addr, align 8 | ||
%arrayidx2 = getelementptr inbounds i64, ptr %3, i64 3 | ||
%4 = load i64, ptr %arrayidx2, align 8 | ||
%5 = load ptr, ptr %vec.addr, align 8 | ||
%arrayidx3 = getelementptr inbounds i64, ptr %5, i64 2 | ||
%6 = load i64, ptr %arrayidx3, align 8 | ||
%sub4 = sub nsw i64 %4, %6 | ||
; CHECK: ldxdw r2, [r1 + 16] | ||
; CHECK: ldxdw r3, [r1 + 24] | ||
; CHECK: sub64 r3, r2 | ||
; CHECK: stxdw [r1 + 8], r3 | ||
%7 = load ptr, ptr %vec.addr, align 8 | ||
%arrayidx5 = getelementptr inbounds i64, ptr %7, i64 1 | ||
store i64 %sub4, ptr %arrayidx5, align 8 | ||
ret void | ||
} | ||
|
||
; Function Attrs: noinline nounwind optnone ssp uwtable(sync) | ||
define void @test_func_32(ptr noundef %vec) #0 { | ||
entry: | ||
; CHECK-LABEL: test_func_32: | ||
%vec.addr = alloca ptr, align 8 | ||
store ptr %vec, ptr %vec.addr, align 8 | ||
%0 = load ptr, ptr %vec.addr, align 8 | ||
%arrayidx = getelementptr inbounds i32, ptr %0, i64 0 | ||
%1 = load i32, ptr %arrayidx, align 4 | ||
%sub = sub nsw i32 50, %1 | ||
; CHECK: ldxw w2, [r1 + 0] | ||
; CHECK: sub32 w2, 50 | ||
; CHECK: stxw [r1 + 0], w2 | ||
%2 = load ptr, ptr %vec.addr, align 8 | ||
%arrayidx1 = getelementptr inbounds i32, ptr %2, i64 0 | ||
store i32 %sub, ptr %arrayidx1, align 4 | ||
%3 = load ptr, ptr %vec.addr, align 8 | ||
%arrayidx2 = getelementptr inbounds i32, ptr %3, i64 3 | ||
%4 = load i32, ptr %arrayidx2, align 4 | ||
%5 = load ptr, ptr %vec.addr, align 8 | ||
%arrayidx3 = getelementptr inbounds i32, ptr %5, i64 2 | ||
%6 = load i32, ptr %arrayidx3, align 4 | ||
%sub4 = sub nsw i32 %4, %6 | ||
; CHECK: ldxw w2, [r1 + 8] | ||
; CHECK: ldxw w3, [r1 + 12] | ||
; CHECK: sub32 w3, w2 | ||
; CHECK: stxw [r1 + 4], w3 | ||
%7 = load ptr, ptr %vec.addr, align 8 | ||
%arrayidx5 = getelementptr inbounds i32, ptr %7, i64 1 | ||
store i32 %sub4, ptr %arrayidx5, align 4 | ||
ret void | ||
} |
This file contains 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 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 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entire part of the patch above involving the
ALU
multiclass and theSUB
definition need to be reworked and simplified. That is, there is no need to refactor and duplicate the multiclass. We can succinctly adjust the original multiclass by conditionally swapping the pattern operands as follows:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One related general question I have is-- should we conditionally be generating the swapped special case
sub
? We need to exactly match the runtime semantics on chain today and down the road.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new syntax can be behind the
sbfv2
cpu perhaps?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find a way to encapsulate the new
sub
inside a predicate forsbfv2
. All the other example cases do not redefine the same instruction. Instead, the predicate encapsulate definitions that only exist for a certain feature and do not override other definitions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything should be behind a feature flag now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for incorporating my offline suggestions, this is ready to land (other than some trivial coding standard nits, which I'll note shortly).