This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add max/min builtins to generate some Zfa instructions from C-code
Needs RevisionPublic

Authored by joshua-arch1 on Mar 22 2023, 10:46 PM.

Details

Summary

To generate FMINM/FMAXM instructions in https://reviews.llvm.org/D143982, we need to use llvm intrinsics in IR files. Now I custom some corresponding builtins in BuiltinsRISCV.def to make sure these instructions can be generated from C codes.
In this implemention, crash mentioned in https://reviews.llvm.org/D144843 will not occur. These builtins can only work in riscv with specific extension.

Diff Detail

Event Timeline

joshua-arch1 created this revision.Mar 22 2023, 10:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 22 2023, 10:46 PM
joshua-arch1 requested review of this revision.Mar 22 2023, 10:46 PM
joshua-arch1 edited the summary of this revision. (Show Details)Mar 22 2023, 10:49 PM
craig.topper requested changes to this revision.Mar 22 2023, 10:54 PM
craig.topper added inline comments.
clang/include/clang/Basic/BuiltinsRISCV.def
83

RISC-V builtins should use RISC-V instruction names

clang/lib/CodeGen/CGBuiltin.cpp
2365

This needs to be in the EmitRISCVBuiltinExpr function.

This revision now requires changes to proceed.Mar 22 2023, 10:54 PM
craig.topper added inline comments.Mar 22 2023, 10:56 PM
clang/include/clang/Basic/BuiltinsRISCV.def
85

as noted in Builtins.def, the letter for _Float16 is 'x' not 'h'

//  x -> half (_Float16)

Update builtin names using corresponding RISCV instructions.

craig.topper added inline comments.Mar 23 2023, 12:53 PM
clang/include/clang/Basic/BuiltinsRISCV.def
84

Should we use _s to match the instruction name, fmaxm.s?

clang/lib/CodeGen/CGBuiltin.cpp
2365

This is still in the wrong place

Update builtin_riscv_fmaxm_f/builtin_riscv_fminm_f to builtin_riscv_fmaxm_s/builtin_riscv_fminm_s

craig.topper requested changes to this revision.Mar 24 2023, 4:55 PM
craig.topper added inline comments.
clang/lib/CodeGen/CGBuiltin.cpp
2366

This needs to be in the RISC-V specific function EmitRISCVBuiltinExpr.

This revision now requires changes to proceed.Mar 24 2023, 4:55 PM