Skip to content
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] Apply IsSignExtendingOpW = 1 on fcvtmod.w.d #69633

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

mshockwave
Copy link
Member

Such that RISCVOptWInstrs can eliminate the redundant sign extend.

Such that RISCVOptWInstrs can eliminate the redundant sign extend.
@llvmbot
Copy link

llvmbot commented Oct 19, 2023

@llvm/pr-subscribers-backend-risc-v

Author: Min-Yih Hsu (mshockwave)

Changes

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 --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
+...

Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mshockwave mshockwave merged commit e353cd8 into llvm:main Oct 19, 2023
4 checks passed
@mshockwave mshockwave deleted the riscv-fcvtmod-sext branch October 19, 2023 21:55
Guzhu-AMD pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Oct 26, 2023
Local branch amd-gfx 2ca870f Merged main:3cac608fbd08 into amd-gfx:97f6261bccf8
Remote branch main e353cd8 [RISCV] Apply `IsSignExtendingOpW = 1` on `fcvtmod.w.d` (llvm#69633)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants