-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV][GISel] Port AddiPair optimization #120463
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
Changes from all commits
Commits
Show all changes
2 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 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,247 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
; RUN: llc -mtriple=riscv32 -global-isel < %s \ | ||
; RUN: | FileCheck %s -check-prefix=RV32I | ||
; RUN: llc -mtriple=riscv64 -global-isel < %s \ | ||
; RUN: | FileCheck %s -check-prefix=RV64I | ||
|
||
; These test how the immediate in an addition is materialized. | ||
|
||
define i32 @add_positive_low_bound_reject(i32 %a) nounwind { | ||
; RV32I-LABEL: add_positive_low_bound_reject: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: addi a0, a0, 2047 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add_positive_low_bound_reject: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: addi a0, a0, 2047 | ||
; RV64I-NEXT: ret | ||
%1 = add i32 %a, 2047 | ||
ret i32 %1 | ||
} | ||
|
||
define i32 @add_positive_low_bound_accept(i32 %a) nounwind { | ||
; RV32I-LABEL: add_positive_low_bound_accept: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: addi a0, a0, 2047 | ||
; RV32I-NEXT: addi a0, a0, 1 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add_positive_low_bound_accept: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: addi a0, a0, 2047 | ||
; RV64I-NEXT: addi a0, a0, 1 | ||
; RV64I-NEXT: ret | ||
%1 = add i32 %a, 2048 | ||
ret i32 %1 | ||
} | ||
|
||
define i32 @add_positive_high_bound_accept(i32 %a) nounwind { | ||
; RV32I-LABEL: add_positive_high_bound_accept: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: addi a0, a0, 2047 | ||
; RV32I-NEXT: addi a0, a0, 2047 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add_positive_high_bound_accept: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: addi a0, a0, 2047 | ||
; RV64I-NEXT: addi a0, a0, 2047 | ||
; RV64I-NEXT: ret | ||
%1 = add i32 %a, 4094 | ||
ret i32 %1 | ||
} | ||
|
||
define i32 @add_positive_high_bound_reject(i32 %a) nounwind { | ||
; RV32I-LABEL: add_positive_high_bound_reject: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: lui a1, 1 | ||
; RV32I-NEXT: addi a1, a1, -1 | ||
; RV32I-NEXT: add a0, a0, a1 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add_positive_high_bound_reject: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: lui a1, 1 | ||
; RV64I-NEXT: addiw a1, a1, -1 | ||
; RV64I-NEXT: add a0, a0, a1 | ||
; RV64I-NEXT: ret | ||
%1 = add i32 %a, 4095 | ||
ret i32 %1 | ||
} | ||
|
||
define i32 @add_negative_high_bound_reject(i32 %a) nounwind { | ||
; RV32I-LABEL: add_negative_high_bound_reject: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: addi a0, a0, -2048 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add_negative_high_bound_reject: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: addi a0, a0, -2048 | ||
; RV64I-NEXT: ret | ||
%1 = add i32 %a, -2048 | ||
ret i32 %1 | ||
} | ||
|
||
define i32 @add_negative_high_bound_accept(i32 %a) nounwind { | ||
; RV32I-LABEL: add_negative_high_bound_accept: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: addi a0, a0, -2048 | ||
; RV32I-NEXT: addi a0, a0, -1 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add_negative_high_bound_accept: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: addi a0, a0, -2048 | ||
; RV64I-NEXT: addi a0, a0, -1 | ||
; RV64I-NEXT: ret | ||
%1 = add i32 %a, -2049 | ||
ret i32 %1 | ||
} | ||
|
||
define i32 @add_negative_low_bound_accept(i32 %a) nounwind { | ||
; RV32I-LABEL: add_negative_low_bound_accept: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: addi a0, a0, -2048 | ||
; RV32I-NEXT: addi a0, a0, -2048 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add_negative_low_bound_accept: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: addi a0, a0, -2048 | ||
; RV64I-NEXT: addi a0, a0, -2048 | ||
; RV64I-NEXT: ret | ||
%1 = add i32 %a, -4096 | ||
ret i32 %1 | ||
} | ||
|
||
define i32 @add_negative_low_bound_reject(i32 %a) nounwind { | ||
; RV32I-LABEL: add_negative_low_bound_reject: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: lui a1, 1048575 | ||
; RV32I-NEXT: addi a1, a1, -1 | ||
; RV32I-NEXT: add a0, a0, a1 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add_negative_low_bound_reject: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: lui a1, 1048575 | ||
; RV64I-NEXT: addiw a1, a1, -1 | ||
; RV64I-NEXT: add a0, a0, a1 | ||
; RV64I-NEXT: ret | ||
%1 = add i32 %a, -4097 | ||
ret i32 %1 | ||
} | ||
|
||
define i32 @add32_accept(i32 %a) nounwind { | ||
; RV32I-LABEL: add32_accept: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: addi a0, a0, 2047 | ||
; RV32I-NEXT: addi a0, a0, 952 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add32_accept: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: addi a0, a0, 2047 | ||
; RV64I-NEXT: addi a0, a0, 952 | ||
; RV64I-NEXT: ret | ||
%1 = add i32 %a, 2999 | ||
ret i32 %1 | ||
} | ||
|
||
define signext i32 @add32_sext_accept(i32 signext %a) nounwind { | ||
; RV32I-LABEL: add32_sext_accept: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: addi a0, a0, 2047 | ||
; RV32I-NEXT: addi a0, a0, 952 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add32_sext_accept: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: addi a0, a0, 2047 | ||
; RV64I-NEXT: addiw a0, a0, 952 | ||
; RV64I-NEXT: ret | ||
%1 = add i32 %a, 2999 | ||
ret i32 %1 | ||
} | ||
|
||
@gv0 = global i32 0, align 4 | ||
define signext i32 @add32_sext_reject_on_rv64(i32 signext %a) nounwind { | ||
; RV32I-LABEL: add32_sext_reject_on_rv64: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: lui a1, %hi(gv0) | ||
; RV32I-NEXT: addi a0, a0, 2047 | ||
; RV32I-NEXT: addi a0, a0, 953 | ||
; RV32I-NEXT: sw a0, %lo(gv0)(a1) | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add32_sext_reject_on_rv64: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: lui a1, %hi(gv0) | ||
; RV64I-NEXT: addi a0, a0, 2047 | ||
; RV64I-NEXT: addiw a0, a0, 953 | ||
; RV64I-NEXT: sw a0, %lo(gv0)(a1) | ||
; RV64I-NEXT: ret | ||
%b = add nsw i32 %a, 3000 | ||
store i32 %b, ptr @gv0, align 4 | ||
ret i32 %b | ||
} | ||
|
||
define i64 @add64_accept(i64 %a) nounwind { | ||
; RV32I-LABEL: add64_accept: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: lui a2, 1 | ||
; RV32I-NEXT: addi a2, a2, -1097 | ||
; RV32I-NEXT: add a0, a0, a2 | ||
; RV32I-NEXT: sltu a2, a0, a2 | ||
; RV32I-NEXT: add a1, a1, a2 | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add64_accept: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: addi a0, a0, 2047 | ||
; RV64I-NEXT: addi a0, a0, 952 | ||
; RV64I-NEXT: ret | ||
%1 = add i64 %a, 2999 | ||
ret i64 %1 | ||
} | ||
|
||
@ga = global i32 0, align 4 | ||
@gb = global i32 0, align 4 | ||
define void @add32_reject() nounwind { | ||
; RV32I-LABEL: add32_reject: | ||
; RV32I: # %bb.0: | ||
; RV32I-NEXT: lui a0, %hi(ga) | ||
; RV32I-NEXT: lui a1, %hi(gb) | ||
; RV32I-NEXT: lw a2, %lo(ga)(a0) | ||
; RV32I-NEXT: lw a3, %lo(gb)(a1) | ||
; RV32I-NEXT: lui a4, 1 | ||
; RV32I-NEXT: addi a4, a4, -1096 | ||
; RV32I-NEXT: add a2, a2, a4 | ||
; RV32I-NEXT: add a3, a3, a4 | ||
; RV32I-NEXT: sw a2, %lo(ga)(a0) | ||
; RV32I-NEXT: sw a3, %lo(gb)(a1) | ||
; RV32I-NEXT: ret | ||
; | ||
; RV64I-LABEL: add32_reject: | ||
; RV64I: # %bb.0: | ||
; RV64I-NEXT: lui a0, %hi(ga) | ||
; RV64I-NEXT: lui a1, %hi(gb) | ||
; RV64I-NEXT: lw a2, %lo(ga)(a0) | ||
; RV64I-NEXT: lw a3, %lo(gb)(a1) | ||
; RV64I-NEXT: lui a4, 1 | ||
; RV64I-NEXT: addi a4, a4, -1096 | ||
; RV64I-NEXT: add a2, a2, a4 | ||
; RV64I-NEXT: add a3, a3, a4 | ||
; RV64I-NEXT: sw a2, %lo(ga)(a0) | ||
; RV64I-NEXT: sw a3, %lo(gb)(a1) | ||
; RV64I-NEXT: ret | ||
%1 = load i32, ptr @ga, align 4 | ||
%2 = load i32, ptr @gb, align 4 | ||
%3 = add i32 %1, 3000 | ||
%4 = add i32 %2, 3000 | ||
store i32 %3, ptr @ga, align 4 | ||
store i32 %4, ptr @gb, align 4 | ||
ret void | ||
} |
Oops, something went wrong.
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.