-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[RISCV] Move strength reduction of mul X, 3/5/9*2^N to combine #89966
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -600,8 +600,9 @@ define i64 @add_mul_combine_infinite_loop(i64 %x) { | |
; RV32IMB-NEXT: sh3add a1, a1, a2 | ||
; RV32IMB-NEXT: sh1add a0, a0, a0 | ||
; RV32IMB-NEXT: slli a2, a0, 3 | ||
; RV32IMB-NEXT: addi a0, a2, 2047 | ||
; RV32IMB-NEXT: addi a0, a0, 1 | ||
; RV32IMB-NEXT: li a3, 1 | ||
; RV32IMB-NEXT: slli a3, a3, 11 | ||
; RV32IMB-NEXT: sh3add a0, a0, a3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case was previously not caught by the "add mul X, 24, Y" pattern because there's two multiplies by 24, and thus it failed the one use check. Instead, it went through generic "mul X, 3 << 2" expansion, and thus ended with the shift/add. With the change, we hit the "(add_like_non_imm12 (shl GPR:$rs1, (XLenVT i)), GPR:$rs2)" pattern - which critically doesn't check if the immediate could be split across two addi. We should probably adjust this, but it seems a) minor, and b) very very separate. (And if we had zbb, this would be a bseti anyways.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This explanation makes sense to me. |
||
; RV32IMB-NEXT: sltu a2, a0, a2 | ||
; RV32IMB-NEXT: add a1, a1, a2 | ||
; RV32IMB-NEXT: ret | ||
|
@@ -610,8 +611,8 @@ define i64 @add_mul_combine_infinite_loop(i64 %x) { | |
; RV64IMB: # %bb.0: | ||
; RV64IMB-NEXT: addi a0, a0, 86 | ||
; RV64IMB-NEXT: sh1add a0, a0, a0 | ||
; RV64IMB-NEXT: li a1, -16 | ||
; RV64IMB-NEXT: sh3add a0, a0, a1 | ||
; RV64IMB-NEXT: slli a0, a0, 3 | ||
; RV64IMB-NEXT: addi a0, a0, -16 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This case was previously picked up by the add_like (mul_one_use X, 24), Y pattern which didn't check whether Y is an immediate or not. |
||
; RV64IMB-NEXT: ret | ||
%tmp0 = mul i64 %x, 24 | ||
%tmp1 = add i64 %tmp0, 2048 | ||
|
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.
Use
SDPatternMatch
?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'm going to leave this as is, and then doing a single NFC to replace several usage examples.