Skip to content

Commit 939f818

Browse files
committed
[RISCV] Split __builtin_riscv_brev8 into _32 and _64 builtin.
Allow _32 builtin on RV64 since it only brev8+sext.w. Part of an effort to remove 'long' to mean XLen from the builtin interface. Matches the proposal here riscv-non-isa/riscv-c-api-doc#44 Reviewed By: asb Differential Revision: https://reviews.llvm.org/D154683
1 parent 345a03b commit 939f818

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

clang/include/clang/Basic/BuiltinsRISCV.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ TARGET_BUILTIN(__builtin_riscv_xperm8_32, "iii", "nc", "zbkx,32bit")
3535
TARGET_BUILTIN(__builtin_riscv_xperm8_64, "WiWiWi", "nc", "zbkx,64bit")
3636

3737
// Zbkb extension
38-
TARGET_BUILTIN(__builtin_riscv_brev8, "LiLi", "nc", "zbkb")
38+
TARGET_BUILTIN(__builtin_riscv_brev8_32, "ii", "nc", "zbkb")
39+
TARGET_BUILTIN(__builtin_riscv_brev8_64, "WiWi", "nc", "zbkb,64bit")
3940
TARGET_BUILTIN(__builtin_riscv_zip_32, "ZiZi", "nc", "zbkb,32bit")
4041
TARGET_BUILTIN(__builtin_riscv_unzip_32, "ZiZi", "nc", "zbkb,32bit")
4142

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20206,7 +20206,8 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
2020620206
case RISCV::BI__builtin_riscv_xperm4_64:
2020720207
case RISCV::BI__builtin_riscv_xperm8_32:
2020820208
case RISCV::BI__builtin_riscv_xperm8_64:
20209-
case RISCV::BI__builtin_riscv_brev8:
20209+
case RISCV::BI__builtin_riscv_brev8_32:
20210+
case RISCV::BI__builtin_riscv_brev8_64:
2021020211
case RISCV::BI__builtin_riscv_zip_32:
2021120212
case RISCV::BI__builtin_riscv_unzip_32: {
2021220213
switch (BuiltinID) {
@@ -20257,7 +20258,8 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
2025720258
break;
2025820259

2025920260
// Zbkb
20260-
case RISCV::BI__builtin_riscv_brev8:
20261+
case RISCV::BI__builtin_riscv_brev8_32:
20262+
case RISCV::BI__builtin_riscv_brev8_64:
2026120263
ID = Intrinsic::riscv_brev8;
2026220264
break;
2026320265
case RISCV::BI__builtin_riscv_zip_32:

clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
// RV32ZBKB-NEXT: [[TMP1:%.*]] = call i32 @llvm.riscv.brev8.i32(i32 [[TMP0]])
1111
// RV32ZBKB-NEXT: ret i32 [[TMP1]]
1212
//
13-
long brev8(long rs1)
13+
int brev8(int rs1)
1414
{
15-
return __builtin_riscv_brev8(rs1);
15+
return __builtin_riscv_brev8_32(rs1);
1616
}
1717

1818
// RV32ZBKB-LABEL: @zip(

clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,28 @@
22
// RUN: %clang_cc1 -triple riscv64 -target-feature +zbkb -emit-llvm %s -o - \
33
// RUN: | FileCheck %s -check-prefix=RV64ZBKB
44

5-
// RV64ZBKB-LABEL: @brev8(
5+
// RV64ZBKB-LABEL: @brev8_32(
6+
// RV64ZBKB-NEXT: entry:
7+
// RV64ZBKB-NEXT: [[RS1_ADDR:%.*]] = alloca i32, align 4
8+
// RV64ZBKB-NEXT: store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
9+
// RV64ZBKB-NEXT: [[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
10+
// RV64ZBKB-NEXT: [[TMP1:%.*]] = call i32 @llvm.riscv.brev8.i32(i32 [[TMP0]])
11+
// RV64ZBKB-NEXT: ret i32 [[TMP1]]
12+
//
13+
int brev8_32(int rs1)
14+
{
15+
return __builtin_riscv_brev8_32(rs1);
16+
}
17+
18+
// RV64ZBKB-LABEL: @brev8_64(
619
// RV64ZBKB-NEXT: entry:
720
// RV64ZBKB-NEXT: [[RS1_ADDR:%.*]] = alloca i64, align 8
821
// RV64ZBKB-NEXT: store i64 [[RS1:%.*]], ptr [[RS1_ADDR]], align 8
922
// RV64ZBKB-NEXT: [[TMP0:%.*]] = load i64, ptr [[RS1_ADDR]], align 8
1023
// RV64ZBKB-NEXT: [[TMP1:%.*]] = call i64 @llvm.riscv.brev8.i64(i64 [[TMP0]])
1124
// RV64ZBKB-NEXT: ret i64 [[TMP1]]
1225
//
13-
long brev8(long rs1)
26+
long brev8_64(long rs1)
1427
{
15-
return __builtin_riscv_brev8(rs1);
28+
return __builtin_riscv_brev8_64(rs1);
1629
}

0 commit comments

Comments
 (0)