[llvm] [RISCV] Apply `IsSignExtendingOpW = 1` on `fcvtmod.w.d` (PR #69633)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 19 12:25:10 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Min-Yih Hsu (mshockwave)
<details>
<summary>Changes</summary>
Such that RISCVOptWInstrs can eliminate the redundant sign extend.
---
Full diff: https://github.com/llvm/llvm-project/pull/69633.diff
2 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td (+1)
- (added) llvm/test/CodeGen/RISCV/opt-w-instrs.mir (+30)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td
index 5d6e8821b85931a..6f88ff7f7ac19af 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZfa.td
@@ -112,6 +112,7 @@ def FROUND_D : FPUnaryOp_r_frm<0b0100001, 0b00100, FPR64, FPR64, "fround.d">,
def FROUNDNX_D : FPUnaryOp_r_frm<0b0100001, 0b00101, FPR64, FPR64, "froundnx.d">,
Sched<[WriteFRoundF64, ReadFRoundF64]>;
+let IsSignExtendingOpW = 1 in
def FCVTMOD_W_D
: FPUnaryOp_r_rtz<0b1100001, 0b01000, GPR, FPR64, "fcvtmod.w.d">,
Sched<[WriteFCvtF64ToI32, ReadFCvtF64ToI32]>;
diff --git a/llvm/test/CodeGen/RISCV/opt-w-instrs.mir b/llvm/test/CodeGen/RISCV/opt-w-instrs.mir
new file mode 100644
index 000000000000000..0ecf8fd6bef33a2
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/opt-w-instrs.mir
@@ -0,0 +1,30 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 3
+# RUN: llc -mtriple=riscv64 -mattr='+d,+zfa' -verify-machineinstrs -run-pass=riscv-opt-w-instrs %s -o - | FileCheck %s --check-prefix=CHECK-ZFA
+
+---
+name: fcvtmod_w_d
+tracksRegLiveness: true
+body: |
+ bb.0.entry:
+ liveins: $x10, $x11
+
+ ; CHECK-ZFA-LABEL: name: fcvtmod_w_d
+ ; CHECK-ZFA: liveins: $x10, $x11
+ ; CHECK-ZFA-NEXT: {{ $}}
+ ; CHECK-ZFA-NEXT: [[COPY:%[0-9]+]]:fpr64 = COPY $x10
+ ; CHECK-ZFA-NEXT: [[COPY1:%[0-9]+]]:gpr = COPY $x11
+ ; CHECK-ZFA-NEXT: [[FCVTMOD_W_D:%[0-9]+]]:gpr = nofpexcept FCVTMOD_W_D [[COPY]], 1
+ ; CHECK-ZFA-NEXT: [[ADD:%[0-9]+]]:gpr = ADD [[COPY1]], [[FCVTMOD_W_D]]
+ ; CHECK-ZFA-NEXT: $x10 = COPY [[ADD]]
+ ; CHECK-ZFA-NEXT: $x11 = COPY [[FCVTMOD_W_D]]
+ ; CHECK-ZFA-NEXT: PseudoRET
+ %0:fpr64 = COPY $x10
+ %1:gpr = COPY $x11
+
+ %2:gpr = nofpexcept FCVTMOD_W_D %0, 1
+ %3:gpr = ADD %1, %2
+ %4:gpr = ADDIW %2, 0
+ $x10 = COPY %3
+ $x11 = COPY %4
+ PseudoRET
+...
``````````
</details>
https://github.com/llvm/llvm-project/pull/69633
More information about the llvm-commits
mailing list