-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] Prefer QC_EXTU to ANDI for certain 12-bit mask immediates #143838
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
Conversation
@llvm/pr-subscribers-backend-risc-v Author: Sudharsan Veeravalli (svs-quic) ChangesQC_EXTU can be compressed to QC_C_EXTU when the immediate is a mask >=63. We currently only handle masks that don't fit in 12-bits in RISCVISelDAGToDAG. I have added patterns than changing code in RISCVISelDAGToDAG since the other extract instructions don't have compressed versions and it is a lot easier to maintain things this way. Full diff: https://github.com/llvm/llvm-project/pull/143838.diff 2 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
index dba035bab928c..9f96a3ed80561 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
@@ -1441,6 +1441,14 @@ let Predicates = [HasVendorXqcibm, IsRV32] in {
def : Pat<(sext_inreg (i32 GPR:$rs1), i16), (QC_EXT GPR:$rs1, 16, 0)>;
def : Pat<(sext_inreg (i32 GPR:$rs1), i8), (QC_EXT GPR:$rs1, 8, 0)>;
def : Pat<(sext_inreg (i32 GPR:$rs1), i1), (QC_EXT GPR:$rs1, 1, 0)>;
+
+// Prefer qc.extu to andi for the following cases since the former can be compressed
+def : Pat<(i32 (and GPRNoX0:$rs, 63)), (QC_EXTU GPRNoX0:$rs, 6, 0)>;
+def : Pat<(i32 (and GPRNoX0:$rs, 127)), (QC_EXTU GPRNoX0:$rs, 7, 0)>;
+def : Pat<(i32 (and GPRNoX0:$rs, 255)), (QC_EXTU GPRNoX0:$rs, 8, 0)>;
+def : Pat<(i32 (and GPRNoX0:$rs, 511)), (QC_EXTU GPRNoX0:$rs, 9, 0)>;
+def : Pat<(i32 (and GPRNoX0:$rs, 1023)), (QC_EXTU GPRNoX0:$rs, 10, 0)>;
+def : Pat<(i32 (and GPRNoX0:$rs, 2047)), (QC_EXTU GPRNoX0:$rs, 11, 0)>;
} // Predicates = [HasVendorXqcibm, IsRV32]
let Predicates = [HasVendorXqciint, IsRV32] in
diff --git a/llvm/test/CodeGen/RISCV/xqcibm-extract.ll b/llvm/test/CodeGen/RISCV/xqcibm-extract.ll
index cb01510058da4..edf6e9a2d5019 100644
--- a/llvm/test/CodeGen/RISCV/xqcibm-extract.ll
+++ b/llvm/test/CodeGen/RISCV/xqcibm-extract.ll
@@ -247,6 +247,48 @@ define i32 @extu_from_and_i32(i32 %x) {
ret i32 %a
}
+define i32 @no_extu_from_and_i32(i32 %x) {
+; RV32I-LABEL: no_extu_from_and_i32:
+; RV32I: # %bb.0:
+; RV32I-NEXT: andi a0, a0, 31
+; RV32I-NEXT: ret
+;
+; RV32XQCIBM-LABEL: no_extu_from_and_i32:
+; RV32XQCIBM: # %bb.0:
+; RV32XQCIBM-NEXT: andi a0, a0, 31
+; RV32XQCIBM-NEXT: ret
+ %a = and i32 %x, 31
+ ret i32 %a
+}
+
+define i32 @extu_from_and_i32_simm12_lb(i32 %x) {
+; RV32I-LABEL: extu_from_and_i32_simm12_lb:
+; RV32I: # %bb.0:
+; RV32I-NEXT: andi a0, a0, 63
+; RV32I-NEXT: ret
+;
+; RV32XQCIBM-LABEL: extu_from_and_i32_simm12_lb:
+; RV32XQCIBM: # %bb.0:
+; RV32XQCIBM-NEXT: qc.extu a0, a0, 6, 0
+; RV32XQCIBM-NEXT: ret
+ %a = and i32 %x, 63
+ ret i32 %a
+}
+
+define i32 @extu_from_and_i32_simm12_ub(i32 %x) {
+; RV32I-LABEL: extu_from_and_i32_simm12_ub:
+; RV32I: # %bb.0:
+; RV32I-NEXT: andi a0, a0, 2047
+; RV32I-NEXT: ret
+;
+; RV32XQCIBM-LABEL: extu_from_and_i32_simm12_ub:
+; RV32XQCIBM: # %bb.0:
+; RV32XQCIBM-NEXT: qc.extu a0, a0, 11, 0
+; RV32XQCIBM-NEXT: ret
+ %a = and i32 %x, 2047
+ ret i32 %a
+}
+
define i64 @extu_from_and_i64(i64 %x) {
; RV32I-LABEL: extu_from_and_i64:
; RV32I: # %bb.0:
|
Can you reread your commit message, looks like you dropped a word in the second paragraph. |
Done. Hopefully it reads better 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.
LGTM
…vm#143838) `QC_EXTU` can be compressed to `QC_C_EXTU` when the immediate is a `mask >=63`. We currently only handle masks that don't fit in 12-bits in `RISCVISelDAGToDAG`. I have added ISEL patterns in `RISCVInstrInfoXqci.td` instead of changing code in `RISCVISelDAGToDAG` since the other extract instructions ( in `XTHeadbb` and `XAndesPerf`) don't have compressed versions and it is a lot easier to maintain things this way.
…vm#143838) `QC_EXTU` can be compressed to `QC_C_EXTU` when the immediate is a `mask >=63`. We currently only handle masks that don't fit in 12-bits in `RISCVISelDAGToDAG`. I have added ISEL patterns in `RISCVInstrInfoXqci.td` instead of changing code in `RISCVISelDAGToDAG` since the other extract instructions ( in `XTHeadbb` and `XAndesPerf`) don't have compressed versions and it is a lot easier to maintain things this way.
QC_EXTU
can be compressed toQC_C_EXTU
when the immediate is amask >=63
. We currently only handle masks that don't fit in 12-bits inRISCVISelDAGToDAG
.I have added ISEL patterns in
RISCVInstrInfoXqci.td
instead of changing code inRISCVISelDAGToDAG
since the other extract instructions ( inXTHeadbb
andXAndesPerf
) don't have compressed versions and it is a lot easier to maintain things this way.