Skip to content

[RISCV][NFC] Use NFList in NFSet #67517

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 1 commit into from
Sep 28, 2023

Conversation

wangpc-pp
Copy link
Contributor

These two subroutines are almost the same except the LMUL encoding.

We can use NFList in NFSet to remove duplicated code.

These two subroutines are almost the same except the LMUL encoding.

We can use `NFList` in `NFSet` to remove duplicated code.
@llvmbot
Copy link
Member

llvmbot commented Sep 27, 2023

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

Changes

These two subroutines are almost the same except the LMUL encoding.

We can use NFList in NFSet to remove duplicated code.


Full diff: https://github.com/llvm/llvm-project/pull/67517.diff

2 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td (+2-4)
  • (modified) llvm/lib/Target/RISCV/RISCVRegisterInfo.td (+5-4)
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
index 0c76e36daf72033..e0d75ef77b76a53 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
@@ -219,10 +219,8 @@ defvar FPListW = [SCALAR_F16, SCALAR_F32];
 defvar BFPListW = [SCALAR_BF16];
 
 class NFSet<LMULInfo m> {
-  list<int> L = !cond(!eq(m.value, V_M8.value): [],
-                      !eq(m.value, V_M4.value): [2],
-                      !eq(m.value, V_M2.value): [2, 3, 4],
-                      true: [2, 3, 4, 5, 6, 7, 8]);
+  defvar lmul = !shl(1, m.value);
+  list<int> L = NFList<lmul>.L;
 }
 
 class octuple_to_str<int octuple> {
diff --git a/llvm/lib/Target/RISCV/RISCVRegisterInfo.td b/llvm/lib/Target/RISCV/RISCVRegisterInfo.td
index 1a6145f92908134..ab0d354967b34c7 100644
--- a/llvm/lib/Target/RISCV/RISCVRegisterInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVRegisterInfo.td
@@ -337,14 +337,15 @@ defvar LMULList = [1, 2, 4, 8];
 // Utility classes for segment load/store.
 //===----------------------------------------------------------------------===//
 // The set of legal NF for LMUL = lmul.
-// LMUL == 1, NF = 2, 3, 4, 5, 6, 7, 8
+// LMUL <= 1, NF = 2, 3, 4, 5, 6, 7, 8
 // LMUL == 2, NF = 2, 3, 4
 // LMUL == 4, NF = 2
+// LMUL == 8, no legal NF
 class NFList<int lmul> {
-  list<int> L = !cond(!eq(lmul, 1): [2, 3, 4, 5, 6, 7, 8],
-                      !eq(lmul, 2): [2, 3, 4],
+  list<int> L = !cond(!eq(lmul, 8): [],
                       !eq(lmul, 4): [2],
-                      !eq(lmul, 8): []);
+                      !eq(lmul, 2): [2, 3, 4],
+                      true: [2, 3, 4, 5, 6, 7, 8]);
 }
 
 // Generate [start, end) SubRegIndex list.

Copy link
Contributor

@michaelmaitland michaelmaitland left a comment

Choose a reason for hiding this comment

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

LGTM.

!eq(m.value, V_M4.value): [2],
!eq(m.value, V_M2.value): [2, 3, 4],
true: [2, 3, 4, 5, 6, 7, 8]);
defvar lmul = !shl(1, m.value);
Copy link
Contributor

Choose a reason for hiding this comment

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

For the fractional LMULs, this encoding gives:

>>> 1 << 0b101
32
>>> 1 << 0b110
64
>>> 1 << 0b111
128

NFList was never used with fractional LMUL in the past. This encoding ends up working out since fractional LMUL will hit the true branch of NFList, but it does diverge from RISCVII::VLMUL encoding which caught my eye. I wanted to say something so we're aware of it, but I am not requesting a change since I think it is fine as this is an implementation detail.

Copy link
Contributor

@michaelmaitland michaelmaitland Sep 27, 2023

Choose a reason for hiding this comment

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

Actually, I think fractional will just take on 0b000 since it’s a 3 bit value. Still fine with me.

Edit: sorry it’s not a 3 bit value I take that back. Please Ignore this comment.

@wangpc-pp wangpc-pp merged commit 4a03ea1 into llvm:main Sep 28, 2023
legrosbuffle pushed a commit to legrosbuffle/llvm-project that referenced this pull request Sep 29, 2023
These two subroutines are almost the same except the LMUL encoding.

We can use `NFList` in `NFSet` to remove duplicated code.
@wangpc-pp wangpc-pp deleted the main-rvv-use-NFList-in-NFSet branch November 24, 2023 04:30
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