[llvm] [RISCV][VLOPT] Avoid crash when user produces scalar def (PR #120255)

Michael Maitland via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 17 08:01:11 PST 2024


https://github.com/michaelmaitland updated https://github.com/llvm/llvm-project/pull/120255

>From c2a83320c1fe454ef780b910ef6bfbc11bd71c1b Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Tue, 17 Dec 2024 06:47:05 -0800
Subject: [PATCH] [RISCV][VLOPT] Avoid crash when user produces scalar def

---
 llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp    |  6 +++---
 .../RISCV/rvv/vl-opt-user-scalar-def.mir      | 21 +++++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)
 create mode 100644 llvm/test/CodeGen/RISCV/rvv/vl-opt-user-scalar-def.mir

diff --git a/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp b/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
index 5f330e272ad0e5..3f6fb4af94b04d 100644
--- a/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
+++ b/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
@@ -938,9 +938,9 @@ bool RISCVVLOptimizer::checkUsers(const MachineOperand *&CommonVL,
     // The SEW and LMUL of destination and source registers need to match.
 
     // We know that MI DEF is a vector register, because that was the guard
-    // to call this function.
-    assert(isVectorRegClass(UserMI.getOperand(0).getReg(), MRI) &&
-           "Expected DEF and USE to be vector registers");
+    // to call this function, so we don't need to assert it.
+    assert(isVectorRegClass(UserOp.getReg(), MRI) &&
+           "Expected consumed operand to be a vector register");
 
     OperandInfo ConsumerInfo = getOperandInfo(UserOp, MRI);
     OperandInfo ProducerInfo = getOperandInfo(MI.getOperand(0), MRI);
diff --git a/llvm/test/CodeGen/RISCV/rvv/vl-opt-user-scalar-def.mir b/llvm/test/CodeGen/RISCV/rvv/vl-opt-user-scalar-def.mir
new file mode 100644
index 00000000000000..bd4d2abb4e008c
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/rvv/vl-opt-user-scalar-def.mir
@@ -0,0 +1,21 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
+# RUN: llc %s -o - -mtriple=riscv32 -mattr=+v -run-pass=riscv-vl-optimizer -verify-machineinstrs | FileCheck %s
+
+---
+name:            vec_instr_with_scalar_def
+tracksRegLiveness: true
+isSSA:           true
+body:             |
+  bb.0:
+    ; CHECK-LABEL: name: vec_instr_with_scalar_def
+    ; CHECK: [[PseudoVMNAND_MM_B8_:%[0-9]+]]:vr = PseudoVMNAND_MM_B8 $noreg, $noreg, -1, 0 /* e8 */
+    ; CHECK-NEXT: [[PseudoVCPOP_M_B1_:%[0-9]+]]:gpr = PseudoVCPOP_M_B1 killed [[PseudoVMNAND_MM_B8_]], -1, 0 /* e8 */
+    ; CHECK-NEXT: [[SLTIU:%[0-9]+]]:gpr = SLTIU killed [[PseudoVCPOP_M_B1_]], 1
+    ; CHECK-NEXT: $x10 = COPY [[SLTIU]]
+    ; CHECK-NEXT: PseudoRET implicit $x10
+    %1:vr = PseudoVMNAND_MM_B8 $noreg, $noreg, -1, 0 /* e8 */
+    %2:gpr = PseudoVCPOP_M_B1 killed %1, -1, 0 /* e8 */
+    %3:gpr = SLTIU killed %2, 1
+    $x10 = COPY %3
+    PseudoRET implicit $x10
+...



More information about the llvm-commits mailing list