Skip to content

Commit 8ab7718

Browse files
authored
[clang][RISCV] Make the index of riscv_tuple_extract and riscv_tuple_insert be truncated rather than zero extended (#111466)
It's illegal if the index is 64 bits and is zero-extend to 32 bits.
1 parent 4e6a6ed commit 8ab7718

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

clang/include/clang/Basic/riscv_vector.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,7 +2564,7 @@ let HasMasked = false, HasVL = false, IRName = "" in {
25642564

25652565
return Builder.CreateIntrinsic(Intrinsic::riscv_tuple_extract,
25662566
{ResultType, Ops[0]->getType()},
2567-
{Ops[0], Builder.CreateZExt(Ops[1],
2567+
{Ops[0], Builder.CreateTrunc(Ops[1],
25682568
Builder.getInt32Ty())});
25692569
}
25702570
}] in {
@@ -2606,7 +2606,7 @@ let HasMasked = false, HasVL = false, IRName = "" in {
26062606
return Builder.CreateIntrinsic(Intrinsic::riscv_tuple_insert,
26072607
{ResultType, Ops[2]->getType()},
26082608
{Ops[0], Ops[2],
2609-
Builder.CreateZExt(Ops[1],Builder.getInt32Ty())});
2609+
Builder.CreateTrunc(Ops[1],Builder.getInt32Ty())});
26102610
}
26112611
}] in {
26122612
foreach dst_lmul = ["(LFixedLog2LMUL:1)", "(LFixedLog2LMUL:2)", "(LFixedLog2LMUL:3)"] in {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 2
2+
// REQUIRES: riscv-registered-target
3+
// RUN: %clang_cc1 -triple riscv64 -target-feature +v -target-feature +zfh \
4+
// RUN: -target-feature +zvfhmin -disable-O0-optnone \
5+
// RUN: -emit-llvm %s -o - | opt -S -passes=mem2reg | \
6+
// RUN: FileCheck --check-prefix=CHECK-RV64 %s
7+
8+
#include <riscv_vector.h>
9+
10+
// CHECK-RV64-LABEL: define dso_local <vscale x 4 x i64> @test_vget_v_u64m4x2_u64m4
11+
// CHECK-RV64-SAME: (target("riscv.vector.tuple", <vscale x 32 x i8>, 2) [[SRC:%.*]]) #[[ATTR0:[0-9]+]] {
12+
// CHECK-RV64-NEXT: entry:
13+
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call <vscale x 4 x i64> @llvm.riscv.tuple.extract.nxv4i64.triscv.vector.tuple_nxv32i8_2t(target("riscv.vector.tuple", <vscale x 32 x i8>, 2) [[SRC]], i32 1)
14+
// CHECK-RV64-NEXT: ret <vscale x 4 x i64> [[TMP0]]
15+
//
16+
vuint64m4_t test_vget_v_u64m4x2_u64m4(vuint64m4x2_t src) {
17+
return __riscv_vget_v_u64m4x2_u64m4(src, 1);
18+
}
19+
20+
// CHECK-RV64-LABEL: define dso_local target("riscv.vector.tuple", <vscale x 32 x i8>, 2) @test_vset_v_u64m4_u64m4x2
21+
// CHECK-RV64-SAME: (target("riscv.vector.tuple", <vscale x 32 x i8>, 2) [[DEST:%.*]], <vscale x 4 x i64> [[VAL:%.*]]) #[[ATTR0]] {
22+
// CHECK-RV64-NEXT: entry:
23+
// CHECK-RV64-NEXT: [[TMP0:%.*]] = call target("riscv.vector.tuple", <vscale x 32 x i8>, 2) @llvm.riscv.tuple.insert.triscv.vector.tuple_nxv32i8_2t.nxv4i64(target("riscv.vector.tuple", <vscale x 32 x i8>, 2) [[DEST]], <vscale x 4 x i64> [[VAL]], i32 1)
24+
// CHECK-RV64-NEXT: ret target("riscv.vector.tuple", <vscale x 32 x i8>, 2) [[TMP0]]
25+
//
26+
vuint64m4x2_t test_vset_v_u64m4_u64m4x2(vuint64m4x2_t dest, vuint64m4_t val) {
27+
return __riscv_vset_v_u64m4_u64m4x2(dest, 1, val);
28+
}

0 commit comments

Comments
 (0)