[RISCV] Implement XcvElw Encoding
Created by: realqhc
This pr implements both encoding and intrinsics of xcvelw. Note that there is a difference between gcc due to possible documentation change.
/* { dg-do compile } */
/* { dg-options "-march=rv32i_xcorevelw1p0 -mabi=ilp32" } */
int var;
int foo1(void* b)
{
return __builtin_riscv_cv_elw(b+8);
}
/* { dg-final { scan-assembler-times "cv\\.elw" 1 } } */
This is the original implementation, and from the documentation the builtin should be uint32_t __builtin_riscv_cv_elw_elw (uint32_t *loc)
.
Hence, the implementation of the builtin in LLVM is
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
// RUN: %clang_cc1 -triple riscv32 -target-feature +xcvelw -emit-llvm %s -o - \
// RUN: | FileCheck %s
// Test __builtin_riscv_cv_elw_elw
#include <stdint.h>
// CHECK-LABEL: @foo1(
// CHECK-NEXT: entry:
// CHECK-NEXT: [[PTR_ADDR:%.*]] = alloca ptr, align 4
// CHECK-NEXT: store ptr [[PTR:%.*]], ptr [[PTR_ADDR]], align 4
// CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[PTR_ADDR]], align 4
// CHECK-NEXT: [[TMP1:%.*]] = call i32 @llvm.riscv.cv.elw.elw(ptr [[TMP0]])
// CHECK-NEXT: ret i32 [[TMP1]]
//
uint32_t foo1(uint32_t *ptr)
{
return __builtin_riscv_cv_elw_elw(ptr);
}