[llvm-branch-commits] [llvm] [RISCV][P-ext] Add tests for extractelement with a variable index. NFC (PR #241041)
Craig Topper via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 11 21:54:15 PST 2026
https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/241041
>From d466a880113a8f394ea17a86de99645aff86ffa8 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 10 Nov 2026 15:03:06 -0800
Subject: [PATCH] [RISCV][P-ext] Add tests for extractelement with a variable
index. NFC
Assisted-by: Claude
---
llvm/test/CodeGen/RISCV/rvp-simd-32.ll | 40 ++++++++++--
llvm/test/CodeGen/RISCV/rvp-simd-64.ll | 84 ++++++++++++++++++++------
2 files changed, 102 insertions(+), 22 deletions(-)
diff --git a/llvm/test/CodeGen/RISCV/rvp-simd-32.ll b/llvm/test/CodeGen/RISCV/rvp-simd-32.ll
index cbc545a46aa2d..83e3568ffe8f8 100644
--- a/llvm/test/CodeGen/RISCV/rvp-simd-32.ll
+++ b/llvm/test/CodeGen/RISCV/rvp-simd-32.ll
@@ -564,6 +564,22 @@ define i16 @test_extract_vector_16_elem1(<2 x i16> %a) {
ret i16 %extracted
}
+define i16 @test_extract_vector_16_variable(<2 x i16> %a, i32 %idx) {
+; RV32-LABEL: test_extract_vector_16_variable:
+; RV32: # %bb.0:
+; RV32-NEXT: slli a1, a1, 4
+; RV32-NEXT: srl a0, a0, a1
+; RV32-NEXT: ret
+;
+; RV64-LABEL: test_extract_vector_16_variable:
+; RV64: # %bb.0:
+; RV64-NEXT: slli.uw a1, a1, 4
+; RV64-NEXT: srl a0, a0, a1
+; RV64-NEXT: ret
+ %res = extractelement <2 x i16> %a, i32 %idx
+ ret i16 %res
+}
+
define i8 @test_extract_vector_8(<4 x i8> %a) {
; CHECK-LABEL: test_extract_vector_8:
; CHECK: # %bb.0:
@@ -581,6 +597,22 @@ define i8 @test_extract_vector_8_elem1(<4 x i8> %a) {
ret i8 %extracted
}
+define i8 @test_extract_vector_8_variable(<4 x i8> %a, i32 %idx) {
+; RV32-LABEL: test_extract_vector_8_variable:
+; RV32: # %bb.0:
+; RV32-NEXT: slli a1, a1, 3
+; RV32-NEXT: srl a0, a0, a1
+; RV32-NEXT: ret
+;
+; RV64-LABEL: test_extract_vector_8_variable:
+; RV64: # %bb.0:
+; RV64-NEXT: slli.uw a1, a1, 3
+; RV64-NEXT: srl a0, a0, a1
+; RV64-NEXT: ret
+ %res = extractelement <4 x i8> %a, i32 %idx
+ ret i8 %res
+}
+
define <2 x i16> @test_insert_vector_16(<2 x i16> %a, i16 %val) {
; RV32-LABEL: test_insert_vector_16:
; RV32: # %bb.0:
@@ -2607,10 +2639,10 @@ define <2 x i16> @test_select_v2i16(i1 %cond, <2 x i16> %a, <2 x i16> %b) {
; CHECK: # %bb.0:
; CHECK-NEXT: andi a3, a0, 1
; CHECK-NEXT: mv a0, a1
-; CHECK-NEXT: bnez a3, .LBB184_2
+; CHECK-NEXT: bnez a3, .LBB186_2
; CHECK-NEXT: # %bb.1:
; CHECK-NEXT: mv a0, a2
-; CHECK-NEXT: .LBB184_2:
+; CHECK-NEXT: .LBB186_2:
; CHECK-NEXT: ret
%res = select i1 %cond, <2 x i16> %a, <2 x i16> %b
ret <2 x i16> %res
@@ -2621,10 +2653,10 @@ define <4 x i8> @test_select_v4i8(i1 %cond, <4 x i8> %a, <4 x i8> %b) {
; CHECK: # %bb.0:
; CHECK-NEXT: andi a3, a0, 1
; CHECK-NEXT: mv a0, a1
-; CHECK-NEXT: bnez a3, .LBB185_2
+; CHECK-NEXT: bnez a3, .LBB187_2
; CHECK-NEXT: # %bb.1:
; CHECK-NEXT: mv a0, a2
-; CHECK-NEXT: .LBB185_2:
+; CHECK-NEXT: .LBB187_2:
; CHECK-NEXT: ret
%res = select i1 %cond, <4 x i8> %a, <4 x i8> %b
ret <4 x i8> %res
diff --git a/llvm/test/CodeGen/RISCV/rvp-simd-64.ll b/llvm/test/CodeGen/RISCV/rvp-simd-64.ll
index 7848ead1f8fcf..f83e0d2a6fd1c 100644
--- a/llvm/test/CodeGen/RISCV/rvp-simd-64.ll
+++ b/llvm/test/CodeGen/RISCV/rvp-simd-64.ll
@@ -1162,6 +1162,30 @@ define i16 @test_extract_vector_16(<4 x i16> %a) {
ret i16 %extracted
}
+define i16 @test_extract_vector_16_variable(<4 x i16> %a, i32 %idx) {
+; RV32-LABEL: test_extract_vector_16_variable:
+; RV32: # %bb.0:
+; RV32-NEXT: addi sp, sp, -16
+; RV32-NEXT: .cfi_def_cfa_offset 16
+; RV32-NEXT: andi a2, a2, 3
+; RV32-NEXT: addi a3, sp, 8
+; RV32-NEXT: sh1add a2, a2, a3
+; RV32-NEXT: sw a0, 8(sp)
+; RV32-NEXT: sw a1, 12(sp)
+; RV32-NEXT: lh a0, 0(a2)
+; RV32-NEXT: addi sp, sp, 16
+; RV32-NEXT: .cfi_def_cfa_offset 0
+; RV32-NEXT: ret
+;
+; RV64-LABEL: test_extract_vector_16_variable:
+; RV64: # %bb.0:
+; RV64-NEXT: slli.uw a1, a1, 4
+; RV64-NEXT: srl a0, a0, a1
+; RV64-NEXT: ret
+ %res = extractelement <4 x i16> %a, i32 %idx
+ ret i16 %res
+}
+
define i8 @test_extract_vector_8(<8 x i8> %a) {
; CHECK-LABEL: test_extract_vector_8:
; CHECK: # %bb.0:
@@ -1170,6 +1194,30 @@ define i8 @test_extract_vector_8(<8 x i8> %a) {
ret i8 %extracted
}
+define i8 @test_extract_vector_8_variable(<8 x i8> %a, i32 %idx) {
+; RV32-LABEL: test_extract_vector_8_variable:
+; RV32: # %bb.0:
+; RV32-NEXT: addi sp, sp, -16
+; RV32-NEXT: .cfi_def_cfa_offset 16
+; RV32-NEXT: andi a2, a2, 7
+; RV32-NEXT: addi a3, sp, 8
+; RV32-NEXT: or a2, a3, a2
+; RV32-NEXT: sw a0, 8(sp)
+; RV32-NEXT: sw a1, 12(sp)
+; RV32-NEXT: lbu a0, 0(a2)
+; RV32-NEXT: addi sp, sp, 16
+; RV32-NEXT: .cfi_def_cfa_offset 0
+; RV32-NEXT: ret
+;
+; RV64-LABEL: test_extract_vector_8_variable:
+; RV64: # %bb.0:
+; RV64-NEXT: slli.uw a1, a1, 3
+; RV64-NEXT: srl a0, a0, a1
+; RV64-NEXT: ret
+ %res = extractelement <8 x i8> %a, i32 %idx
+ ret i8 %res
+}
+
define i32 @test_extract_vector_32(<2 x i32> %a) {
; CHECK-LABEL: test_extract_vector_32:
; CHECK: # %bb.0:
@@ -4995,12 +5043,12 @@ define <4 x i16> @test_select_v4i16(i1 %cond, <4 x i16> %a, <4 x i16> %b) {
; RV32-LABEL: test_select_v4i16:
; RV32: # %bb.0:
; RV32-NEXT: andi a5, a0, 1
-; RV32-NEXT: bnez a5, .LBB268_2
+; RV32-NEXT: bnez a5, .LBB270_2
; RV32-NEXT: # %bb.1:
; RV32-NEXT: mv a0, a3
; RV32-NEXT: mv a1, a4
; RV32-NEXT: ret
-; RV32-NEXT: .LBB268_2:
+; RV32-NEXT: .LBB270_2:
; RV32-NEXT: mv a0, a1
; RV32-NEXT: mv a1, a2
; RV32-NEXT: ret
@@ -5009,10 +5057,10 @@ define <4 x i16> @test_select_v4i16(i1 %cond, <4 x i16> %a, <4 x i16> %b) {
; RV64: # %bb.0:
; RV64-NEXT: andi a3, a0, 1
; RV64-NEXT: mv a0, a1
-; RV64-NEXT: bnez a3, .LBB268_2
+; RV64-NEXT: bnez a3, .LBB270_2
; RV64-NEXT: # %bb.1:
; RV64-NEXT: mv a0, a2
-; RV64-NEXT: .LBB268_2:
+; RV64-NEXT: .LBB270_2:
; RV64-NEXT: ret
%res = select i1 %cond, <4 x i16> %a, <4 x i16> %b
ret <4 x i16> %res
@@ -5022,12 +5070,12 @@ define <8 x i8> @test_select_v8i8(i1 %cond, <8 x i8> %a, <8 x i8> %b) {
; RV32-LABEL: test_select_v8i8:
; RV32: # %bb.0:
; RV32-NEXT: andi a5, a0, 1
-; RV32-NEXT: bnez a5, .LBB269_2
+; RV32-NEXT: bnez a5, .LBB271_2
; RV32-NEXT: # %bb.1:
; RV32-NEXT: mv a0, a3
; RV32-NEXT: mv a1, a4
; RV32-NEXT: ret
-; RV32-NEXT: .LBB269_2:
+; RV32-NEXT: .LBB271_2:
; RV32-NEXT: mv a0, a1
; RV32-NEXT: mv a1, a2
; RV32-NEXT: ret
@@ -5036,10 +5084,10 @@ define <8 x i8> @test_select_v8i8(i1 %cond, <8 x i8> %a, <8 x i8> %b) {
; RV64: # %bb.0:
; RV64-NEXT: andi a3, a0, 1
; RV64-NEXT: mv a0, a1
-; RV64-NEXT: bnez a3, .LBB269_2
+; RV64-NEXT: bnez a3, .LBB271_2
; RV64-NEXT: # %bb.1:
; RV64-NEXT: mv a0, a2
-; RV64-NEXT: .LBB269_2:
+; RV64-NEXT: .LBB271_2:
; RV64-NEXT: ret
%res = select i1 %cond, <8 x i8> %a, <8 x i8> %b
ret <8 x i8> %res
@@ -5049,12 +5097,12 @@ define <2 x i32> @test_select_v2i32(i1 %cond, <2 x i32> %a, <2 x i32> %b) {
; RV32-LABEL: test_select_v2i32:
; RV32: # %bb.0:
; RV32-NEXT: andi a5, a0, 1
-; RV32-NEXT: bnez a5, .LBB270_2
+; RV32-NEXT: bnez a5, .LBB272_2
; RV32-NEXT: # %bb.1:
; RV32-NEXT: mv a0, a3
; RV32-NEXT: mv a1, a4
; RV32-NEXT: ret
-; RV32-NEXT: .LBB270_2:
+; RV32-NEXT: .LBB272_2:
; RV32-NEXT: mv a0, a1
; RV32-NEXT: mv a1, a2
; RV32-NEXT: ret
@@ -5063,10 +5111,10 @@ define <2 x i32> @test_select_v2i32(i1 %cond, <2 x i32> %a, <2 x i32> %b) {
; RV64: # %bb.0:
; RV64-NEXT: andi a3, a0, 1
; RV64-NEXT: mv a0, a1
-; RV64-NEXT: bnez a3, .LBB270_2
+; RV64-NEXT: bnez a3, .LBB272_2
; RV64-NEXT: # %bb.1:
; RV64-NEXT: mv a0, a2
-; RV64-NEXT: .LBB270_2:
+; RV64-NEXT: .LBB272_2:
; RV64-NEXT: ret
%res = select i1 %cond, <2 x i32> %a, <2 x i32> %b
ret <2 x i32> %res
@@ -5114,16 +5162,16 @@ define <2 x i32> @test_vselect_v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) {
; RV32: # %bb.0:
; RV32-NEXT: pmslt.dw a6, a2, a0
; RV32-NEXT: mv a0, a4
-; RV32-NEXT: beqz a7, .LBB273_3
+; RV32-NEXT: beqz a7, .LBB275_3
; RV32-NEXT: # %bb.1:
-; RV32-NEXT: beqz a6, .LBB273_4
-; RV32-NEXT: .LBB273_2:
+; RV32-NEXT: beqz a6, .LBB275_4
+; RV32-NEXT: .LBB275_2:
; RV32-NEXT: mv a1, a5
; RV32-NEXT: ret
-; RV32-NEXT: .LBB273_3:
+; RV32-NEXT: .LBB275_3:
; RV32-NEXT: mv a5, a3
-; RV32-NEXT: bnez a6, .LBB273_2
-; RV32-NEXT: .LBB273_4:
+; RV32-NEXT: bnez a6, .LBB275_2
+; RV32-NEXT: .LBB275_4:
; RV32-NEXT: mv a0, a2
; RV32-NEXT: mv a1, a5
; RV32-NEXT: ret
More information about the llvm-branch-commits
mailing list