Skip to content

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Sep 5, 2025

This just reorders existing so we do the legal type check first.

In this particular test case we're also protected by the i1 check that I also moved earlier.

Fixes #157177.

…atchSplatAsGather.

This just reorders existing so we do the legal type check first.

In this particular test case we're also protected by the i1 check
that I also moved earlier.

Fixes llvm#157177.
@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2025

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

Author: Craig Topper (topperc)

Changes

This just reorders existing so we do the legal type check first.

In this particular test case we're also protected by the i1 check that I also moved earlier.

Fixes #157177.


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

2 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+4-2)
  • (added) llvm/test/CodeGen/RISCV/rvv/pr157177.ll (+20)
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 44434ff51288f..a27bd418a6b01 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -3744,9 +3744,11 @@ static SDValue matchSplatAsGather(SDValue SplatVal, MVT VT, const SDLoc &DL,
   // different
   // FIXME: Support i1 vectors, maybe by promoting to i8?
   MVT EltTy = VT.getVectorElementType();
+  if (EltTy == MVT::i1 ||
+      !DAG.getTargetLoweringInfo().isTypeLegal(Src.getValueType()))
+    return SDValue();
   MVT SrcVT = Src.getSimpleValueType();
-  if (EltTy == MVT::i1 || EltTy != SrcVT.getVectorElementType() ||
-      !DAG.getTargetLoweringInfo().isTypeLegal(SrcVT))
+  if (EltTy != SrcVT.getVectorElementType())
     return SDValue();
   SDValue Idx = SplatVal.getOperand(1);
   // The index must be a legal type.
diff --git a/llvm/test/CodeGen/RISCV/rvv/pr157177.ll b/llvm/test/CodeGen/RISCV/rvv/pr157177.ll
new file mode 100644
index 0000000000000..adf857f833a47
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/rvv/pr157177.ll
@@ -0,0 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc < %s -mtriple=riscv64 -mattr=+v | FileCheck %s
+
+define <vscale x 8 x i1> @main(<120 x i1> %0) #0 {
+; CHECK-LABEL: main:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    li a0, 128
+; CHECK-NEXT:    vsetvli zero, a0, e8, m8, ta, ma
+; CHECK-NEXT:    vfirst.m a0, v0
+; CHECK-NEXT:    seqz a0, a0
+; CHECK-NEXT:    vsetvli a1, zero, e8, m1, ta, ma
+; CHECK-NEXT:    vmv.v.x v8, a0
+; CHECK-NEXT:    vmsne.vi v0, v8, 0
+; CHECK-NEXT:    ret
+entry:
+  %1 = extractelement <120 x i1> %0, i64 0
+  %2 = insertelement <vscale x 8 x i1> zeroinitializer, i1 %1, i64 0
+  %3 = shufflevector <vscale x 8 x i1> %2, <vscale x 8 x i1> zeroinitializer, <vscale x 8 x i32> zeroinitializer
+  ret <vscale x 8 x i1> %3
+}

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.

@topperc topperc merged commit 151c6ed into llvm:main Sep 6, 2025
11 checks passed
@topperc topperc deleted the pr/pr157177 branch September 6, 2025 05:00
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.

[RISC-V] Assertion `isSimple() && "Expected a SimpleValueType!"' failed.
3 participants