Skip to content

Commit

Permalink
[RISCV] Split __builtin_riscv_brev8 into _32 and _64 builtin.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
topperc authored and veselypeta committed Sep 4, 2024
2 parents f314b29 + 939f818 commit 78b12f7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
3 changes: 2 additions & 1 deletion clang/include/clang/Basic/BuiltinsRISCV.def
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ TARGET_BUILTIN(__builtin_riscv_xperm8_32, "iii", "nc", "zbkx,32bit")
TARGET_BUILTIN(__builtin_riscv_xperm8_64, "WiWiWi", "nc", "zbkx,64bit")

// Zbkb extension
TARGET_BUILTIN(__builtin_riscv_brev8, "LiLi", "nc", "zbkb")
TARGET_BUILTIN(__builtin_riscv_brev8_32, "ii", "nc", "zbkb")
TARGET_BUILTIN(__builtin_riscv_brev8_64, "WiWi", "nc", "zbkb,64bit")
TARGET_BUILTIN(__builtin_riscv_zip_32, "ZiZi", "nc", "zbkb,32bit")
TARGET_BUILTIN(__builtin_riscv_unzip_32, "ZiZi", "nc", "zbkb,32bit")

Expand Down
6 changes: 4 additions & 2 deletions clang/lib/CodeGen/CGBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20588,7 +20588,8 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
case RISCV::BI__builtin_riscv_xperm4_64:
case RISCV::BI__builtin_riscv_xperm8_32:
case RISCV::BI__builtin_riscv_xperm8_64:
case RISCV::BI__builtin_riscv_brev8:
case RISCV::BI__builtin_riscv_brev8_32:
case RISCV::BI__builtin_riscv_brev8_64:
case RISCV::BI__builtin_riscv_zip_32:
case RISCV::BI__builtin_riscv_unzip_32: {
switch (BuiltinID) {
Expand Down Expand Up @@ -20639,7 +20640,8 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
break;

// Zbkb
case RISCV::BI__builtin_riscv_brev8:
case RISCV::BI__builtin_riscv_brev8_32:
case RISCV::BI__builtin_riscv_brev8_64:
ID = Intrinsic::riscv_brev8;
break;
case RISCV::BI__builtin_riscv_zip_32:
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbkb.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
// RV32ZBKB-NEXT: [[TMP1:%.*]] = call i32 @llvm.riscv.brev8.i32(i32 [[TMP0]])
// RV32ZBKB-NEXT: ret i32 [[TMP1]]
//
long brev8(long rs1)
int brev8(int rs1)
{
return __builtin_riscv_brev8(rs1);
return __builtin_riscv_brev8_32(rs1);
}

// RV32ZBKB-LABEL: @zip(
Expand Down
19 changes: 16 additions & 3 deletions clang/test/CodeGen/RISCV/rvb-intrinsics/riscv64-zbkb.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
// RUN: %clang_cc1 -triple riscv64 -target-feature +zbkb -emit-llvm %s -o - \
// RUN: | FileCheck %s -check-prefix=RV64ZBKB

// RV64ZBKB-LABEL: @brev8(
// RV64ZBKB-LABEL: @brev8_32(
// RV64ZBKB-NEXT: entry:
// RV64ZBKB-NEXT: [[RS1_ADDR:%.*]] = alloca i32, align 4
// RV64ZBKB-NEXT: store i32 [[RS1:%.*]], ptr [[RS1_ADDR]], align 4
// RV64ZBKB-NEXT: [[TMP0:%.*]] = load i32, ptr [[RS1_ADDR]], align 4
// RV64ZBKB-NEXT: [[TMP1:%.*]] = call i32 @llvm.riscv.brev8.i32(i32 [[TMP0]])
// RV64ZBKB-NEXT: ret i32 [[TMP1]]
//
int brev8_32(int rs1)
{
return __builtin_riscv_brev8_32(rs1);
}

// RV64ZBKB-LABEL: @brev8_64(
// RV64ZBKB-NEXT: entry:
// RV64ZBKB-NEXT: [[RS1_ADDR:%.*]] = alloca i64, align 8
// RV64ZBKB-NEXT: store i64 [[RS1:%.*]], ptr [[RS1_ADDR]], align 8
// RV64ZBKB-NEXT: [[TMP0:%.*]] = load i64, ptr [[RS1_ADDR]], align 8
// RV64ZBKB-NEXT: [[TMP1:%.*]] = call i64 @llvm.riscv.brev8.i64(i64 [[TMP0]])
// RV64ZBKB-NEXT: ret i64 [[TMP1]]
//
long brev8(long rs1)
long brev8_64(long rs1)
{
return __builtin_riscv_brev8(rs1);
return __builtin_riscv_brev8_64(rs1);
}

0 comments on commit 78b12f7

Please sign in to comment.