This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Add clang builtins for CLZ instruction.
ClosedPublic

Authored by joker881 on Mar 17 2022, 8:06 AM.

Details

Diff Detail

Event Timeline

joker881 created this revision.Mar 17 2022, 8:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 8:06 AM
joker881 requested review of this revision.Mar 17 2022, 8:06 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 17 2022, 8:06 AM
joker881 retitled this revision from [RISCV][1/2]Add IR intrinsic for Zbb extension to [RISCV] CLZ Instruction.Mar 17 2022, 8:21 AM
joker881 edited the summary of this revision. (Show Details)

These were intentionally not added because llvm has generic leading and trailing zero builtins. builtin_clz and builtin_ctz

Rethinking that. Since builtin_clz is undefined for 0, I think we should have clang builtins, but we should use llvm.ctlz with false for the second argument as their implementation. See X86::BIbuiltin_ia32_lzcnt_u32 for example.

joker881 updated this revision to Diff 421931.EditedApr 11 2022, 7:57 AM

[RISCV]CLZ instruction try use llvm.ctlz with false for the second argument to implement clz

craig.topper added inline comments.Apr 11 2022, 9:16 AM
clang/lib/CodeGen/CGBuiltin.cpp
19048

Add a space before the opening curly brace

19051

Fix the clang-format warning here

clang/test/CodeGen/RISCV/rvb-intrinsics/riscv32-zbb.c
21

There is no llvm.riscv.clz.i32 intrinsic. Was this test not updated?

joker881 updated this revision to Diff 422457.Apr 13 2022, 3:45 AM

upadated test files, fixed the format problem

wait ,It seems the format problem have not solved,sorry

joker881 updated this revision to Diff 422485.Apr 13 2022, 5:19 AM

upadated test files, fixed the format problem

joker881 updated this revision to Diff 422487.Apr 13 2022, 5:39 AM

upadated test files, fixed the format problem

craig.topper accepted this revision.Apr 13 2022, 4:44 PM

LGTM though I think the title needs to be updated. Should be something like "[RISCV] Add clang builtins for CLZ instruction."

This revision is now accepted and ready to land.Apr 13 2022, 4:44 PM
joker881 retitled this revision from [RISCV] CLZ Instruction to RISCV] Add clang builtins for CLZ instruction..Apr 13 2022, 8:15 PM
This revision was landed with ongoing or failed builds.Apr 13 2022, 9:29 PM
This revision was automatically updated to reflect the committed changes.
joker881 retitled this revision from RISCV] Add clang builtins for CLZ instruction. to [RISCV] Add clang builtins for CLZ instruction..Apr 13 2022, 9:30 PM