Skip to content

[RISCV] Reduce VL of vmerge.vvm's true operand #105786

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
Aug 26, 2024

Conversation

lukel97
Copy link
Contributor

@lukel97 lukel97 commented Aug 23, 2024

This extends the peephole added in #104689 to also reduce the VL of a PseudoVMERGE_VVM's true operand.

We could extend this later to reduce the false operand as well, but this starts with just the true operand since it allows vmerges that are converted to vmv.v.vs (convertVMergeToVMv) to be potentially further folded into their source (foldVMV_V_V).

@llvmbot
Copy link
Member

llvmbot commented Aug 23, 2024

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

Author: Luke Lau (lukel97)

Changes

This extends the peephole added in #104689 to also reduce the VL of a PseudoVMERGE_VVM's true operand.

We could extend this later to reduce the false operand as well, but this starts with just the true operand since it allows vmerges that are converted to vmv.v.vs (convertVMergeToVMv) to be potentially further folded into their source (foldVMV_V_V).


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

2 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp (+3)
  • (modified) llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-vops.ll (+1-2)
diff --git a/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp b/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
index 9772782ad3d6db..8eb1586799f5e8 100644
--- a/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
+++ b/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
@@ -131,6 +131,9 @@ bool RISCVVectorPeephole::tryToReduceVL(MachineInstr &MI) const {
   case RISCV::VMV_V_V:
     SrcIdx = 2;
     break;
+  case RISCV::VMERGE_VVM:
+    SrcIdx = 3; // TODO: We can also handle the false operand.
+    break;
   }
 
   MachineOperand &VL = MI.getOperand(RISCVII::getVLOpNum(MI.getDesc()));
diff --git a/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-vops.ll b/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-vops.ll
index 39055dc5adfcf7..6700920cebff0a 100644
--- a/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-vops.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-vops.ll
@@ -1072,9 +1072,8 @@ define <vscale x 2 x i32> @vmerge_larger_vl_same_passthru(<vscale x 2 x i32> %pa
 define <vscale x 2 x i32> @vmerge_smaller_vl_different_passthru(<vscale x 2 x i32> %pt1, <vscale x 2 x i32> %pt2, <vscale x 2 x i32> %x, <vscale x 2 x i32> %y, <vscale x 2 x i1> %m) {
 ; CHECK-LABEL: vmerge_smaller_vl_different_passthru:
 ; CHECK:       # %bb.0:
-; CHECK-NEXT:    vsetivli zero, 3, e32, m1, tu, ma
-; CHECK-NEXT:    vadd.vv v8, v10, v11
 ; CHECK-NEXT:    vsetivli zero, 2, e32, m1, tu, ma
+; CHECK-NEXT:    vadd.vv v8, v10, v11
 ; CHECK-NEXT:    vmerge.vvm v9, v9, v8, v0
 ; CHECK-NEXT:    vmv1r.v v8, v9
 ; CHECK-NEXT:    ret

This extends the peephole added in llvm#104689 to also reduce the VL of a PseudoVMERGE_VVM's true operand.

We could extend this later to reduce the false operand as well, but this starts with just the true operand since it allows vmerges that are converted to vmv.v.vs (convertVMergeToVMv) to be potentially further folded into their source (foldVMV_V_V).
@lukel97 lukel97 force-pushed the vector-peephole-reduce-vmerge-vl branch from d476887 to 05c66d9 Compare August 23, 2024 06:40
Copy link
Contributor

@wangpc-pp wangpc-pp left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Collaborator

@preames preames left a comment

Choose a reason for hiding this comment

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

LGTM

@lukel97 lukel97 merged commit c073821 into llvm:main Aug 26, 2024
6 of 8 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 26, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-fullbuild-dbg running on libc-x86_64-debian-fullbuild while building llvm at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/179/builds/4984

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[ RUN      ] LlvmLibcVASPrintfTest.PercentConv
[       OK ] LlvmLibcVASPrintfTest.PercentConv (8 us)
[ RUN      ] LlvmLibcVASPrintfTest.CharConv
[       OK ] LlvmLibcVASPrintfTest.CharConv (9 us)
[ RUN      ] LlvmLibcVASPrintfTest.LargeStringNoConv
[       OK ] LlvmLibcVASPrintfTest.LargeStringNoConv (24 us)
[ RUN      ] LlvmLibcVASPrintfTest.ManyReAlloc
[       OK ] LlvmLibcVASPrintfTest.ManyReAlloc (13 us)
Ran 5 tests.  PASS: 5  FAIL: 0
[817/1074] Running unit test libc.test.src.stdio.fscanf_test.__unit__
FAILED: projects/libc/test/src/stdio/CMakeFiles/libc.test.src.stdio.fscanf_test.__unit__ /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/projects/libc/test/src/stdio/CMakeFiles/libc.test.src.stdio.fscanf_test.__unit__ 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/projects/libc/test/src/stdio && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/projects/libc/test/src/stdio/libc.test.src.stdio.fscanf_test.__unit__.__build__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFScanfTest.WriteToFile
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/libc/test/src/stdio/fscanf_test.cpp:73: FAILURE
      Expected: read
      Which is: 0
To be equal to: 1
      Which is: 1
[  FAILED  ] LlvmLibcFScanfTest.WriteToFile
Ran 1 tests.  PASS: 0  FAIL: 1
[818/1074] Running unit test libc.test.src.stdio.vfscanf_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFScanfTest.WriteToFile
[       OK ] LlvmLibcFScanfTest.WriteToFile (266 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[819/1074] Running unit test libc.test.src.stdio.vsscanf_test.__unit__
[==========] Running 4 tests from 1 test suite.
[ RUN      ] LlvmLibcVSScanfTest.SimpleStringConv
[       OK ] LlvmLibcVSScanfTest.SimpleStringConv (21 us)
[ RUN      ] LlvmLibcVSScanfTest.IntConvSimple
[       OK ] LlvmLibcVSScanfTest.IntConvSimple (21 us)
[ RUN      ] LlvmLibcVSScanfTest.IntConvLengthModifier
[       OK ] LlvmLibcVSScanfTest.IntConvLengthModifier (15 us)
[ RUN      ] LlvmLibcVSScanfTest.IntConvBaseSelection
[       OK ] LlvmLibcVSScanfTest.IntConvBaseSelection (5 us)
Ran 4 tests.  PASS: 4  FAIL: 0
[820/1074] Running unit test libc.test.src.stdio.sscanf_test.__unit__
[==========] Running 15 tests from 1 test suite.
[ RUN      ] LlvmLibcSScanfTest.SimpleStringConv
[       OK ] LlvmLibcSScanfTest.SimpleStringConv (19 us)
[ RUN      ] LlvmLibcSScanfTest.IntConvSimple
[       OK ] LlvmLibcSScanfTest.IntConvSimple (16 us)
[ RUN      ] LlvmLibcSScanfTest.IntConvLengthModifier
[       OK ] LlvmLibcSScanfTest.IntConvLengthModifier (11 us)
[ RUN      ] LlvmLibcSScanfTest.IntConvBaseSelection
[       OK ] LlvmLibcSScanfTest.IntConvBaseSelection (4 us)
[ RUN      ] LlvmLibcSScanfTest.IntConvMaxLengthTests
[       OK ] LlvmLibcSScanfTest.IntConvMaxLengthTests (8 us)
Step 8 (libc-unit-tests) failure: libc-unit-tests (failure)
...
[ RUN      ] LlvmLibcVASPrintfTest.PercentConv
[       OK ] LlvmLibcVASPrintfTest.PercentConv (8 us)
[ RUN      ] LlvmLibcVASPrintfTest.CharConv
[       OK ] LlvmLibcVASPrintfTest.CharConv (9 us)
[ RUN      ] LlvmLibcVASPrintfTest.LargeStringNoConv
[       OK ] LlvmLibcVASPrintfTest.LargeStringNoConv (24 us)
[ RUN      ] LlvmLibcVASPrintfTest.ManyReAlloc
[       OK ] LlvmLibcVASPrintfTest.ManyReAlloc (13 us)
Ran 5 tests.  PASS: 5  FAIL: 0
[817/1074] Running unit test libc.test.src.stdio.fscanf_test.__unit__
FAILED: projects/libc/test/src/stdio/CMakeFiles/libc.test.src.stdio.fscanf_test.__unit__ /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/projects/libc/test/src/stdio/CMakeFiles/libc.test.src.stdio.fscanf_test.__unit__ 
cd /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/projects/libc/test/src/stdio && /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/build/projects/libc/test/src/stdio/libc.test.src.stdio.fscanf_test.__unit__.__build__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFScanfTest.WriteToFile
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/libc/test/src/stdio/fscanf_test.cpp:73: FAILURE
      Expected: read
      Which is: 0
To be equal to: 1
      Which is: 1
[  FAILED  ] LlvmLibcFScanfTest.WriteToFile
Ran 1 tests.  PASS: 0  FAIL: 1
[818/1074] Running unit test libc.test.src.stdio.vfscanf_test.__unit__
[==========] Running 1 test from 1 test suite.
[ RUN      ] LlvmLibcFScanfTest.WriteToFile
[       OK ] LlvmLibcFScanfTest.WriteToFile (266 us)
Ran 1 tests.  PASS: 1  FAIL: 0
[819/1074] Running unit test libc.test.src.stdio.vsscanf_test.__unit__
[==========] Running 4 tests from 1 test suite.
[ RUN      ] LlvmLibcVSScanfTest.SimpleStringConv
[       OK ] LlvmLibcVSScanfTest.SimpleStringConv (21 us)
[ RUN      ] LlvmLibcVSScanfTest.IntConvSimple
[       OK ] LlvmLibcVSScanfTest.IntConvSimple (21 us)
[ RUN      ] LlvmLibcVSScanfTest.IntConvLengthModifier
[       OK ] LlvmLibcVSScanfTest.IntConvLengthModifier (15 us)
[ RUN      ] LlvmLibcVSScanfTest.IntConvBaseSelection
[       OK ] LlvmLibcVSScanfTest.IntConvBaseSelection (5 us)
Ran 4 tests.  PASS: 4  FAIL: 0
[820/1074] Running unit test libc.test.src.stdio.sscanf_test.__unit__
[==========] Running 15 tests from 1 test suite.
[ RUN      ] LlvmLibcSScanfTest.SimpleStringConv
[       OK ] LlvmLibcSScanfTest.SimpleStringConv (19 us)
[ RUN      ] LlvmLibcSScanfTest.IntConvSimple
[       OK ] LlvmLibcSScanfTest.IntConvSimple (16 us)
[ RUN      ] LlvmLibcSScanfTest.IntConvLengthModifier
[       OK ] LlvmLibcSScanfTest.IntConvLengthModifier (11 us)
[ RUN      ] LlvmLibcSScanfTest.IntConvBaseSelection
[       OK ] LlvmLibcSScanfTest.IntConvBaseSelection (4 us)
[ RUN      ] LlvmLibcSScanfTest.IntConvMaxLengthTests
[       OK ] LlvmLibcSScanfTest.IntConvMaxLengthTests (8 us)

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.

5 participants