[CIR] Upstream handling of X86 builtins
Overview
This is an umbrella task for all X86 builtin upstreaming. There are enough X86-specific builtins that creating separate issues for each logical group is not practical. Many people can work on this in parallel, if we can successfully coordinate the work to avoid overlap as much as possible. To that end, I am adding a partial list here of the builtins that need to be upstreamed. If you would like to contribute to this task, please comment saying which builtin(s) you are working on.
I will remove builtins from this list as they are upstreamed.
Please check the table below before beginning work to make sure no one else is working on the builtins you are targeting. If you have any questions, please comment here tagging @andykaylor.
Needed builtins
| Builtin group | Assignee |
|---|---|
| rdtsc, rdtscp | @adit4443ya |
| lzcnt, tzcnt | @Luhaocong |
| undef | @Thibault-Monnier |
| vec_ext | @Thibault-Monnier |
| vec_set | @jacquesguan |
| xsave, xrstor | @medhatiwari |
| masked store | @woruyu |
| masked load | @woruyu |
| convert to mask | @MarwanTarik |
| compress store | @AnkitDubeycs25 |
| gather | @badumbatish |
| scatter | @badumbatish |
| vinsert, shuffle, blend , perm | @Thibault-Monnier |
Many more builtins are needed but not yet implemented in the incubator. I will create a separate issue for that. work.
Existing incubator tests
clang/test/CIR/CodeGen/X86/*
Hi!
This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
- Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
- Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
- Fix the issue locally.
- Run the test suite locally. Remember that the subdirectories under
test/create fine-grained testing targets, so you can e.g. usemake check-clang-astto only run Clang's AST tests. - Create a Git commit.
- Run
git clang-format HEAD~1to format your changes. - Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.
@llvm/issue-subscribers-good-first-issue
Author: Andy Kaylor (andykaylor)
I will remove builtins from this list as they are upstreamed.
Please check the table below before beginning work to make sure no one else is working on the builtins you are targeting. If you have any questions, please comment here tagging @andykaylor.
Needed builtins
| Builtin group | Assignee |
|---|---|
| rdtsc, rdtscp | |
| lzcnt, tzcnt | |
| undef | |
| vec_ext | |
| vec_set | |
| xsave, xrstor | |
| masked store | |
| masked load | |
| convert to mask | |
| compress store | |
| gather | |
| scatter | |
| vinsert, shuffle, blend , perm |
Many more builtins are needed but not yet implemented in the incubator. I will create a separate issue for that. work.
Existing incubator tests
clang/test/CIR/CodeGen/X86/*
I have marked this as a "good first issue" but interested contributors should be aware of some special handling needed for working on ClangIR issues.
First, in order to even reproduce the problem you will need to build clang with ClangIR enabled. By default, clang does not build ClangIR support. You can find instructions for building with ClangIR enabled here.
Second, after building but before starting any other work, you should verify that you see an error when compiling the suggested minimal test case with ClangIR enabled. You should see an error (in this case, ``) when you compile the test case using the following options: -fclangir -emit-cir. The error may be followed by other errors or a stack dump. If you do not see an error, either someone else has already implemented this feature, or you are using the wrong repository (perhaps you built the ClangIR incubator repository?).
Third, the code to implement this feature is already present in the ClangIR incubator repository. The task here is to find the correct code, migrate it to the main LLVM repository, and creating a pull request to merge it there. As part of the migration process, you may need to update the code to conform to the coding standards used in the LLVM project. You will also need to create or migrate a LIT test that exercises the new code.
Don't hesitate to ask for help if you need it. The entire point of "good first issue" is to help new people get involved with our project.
@Thibault-Monnier @woruyu @HendrikHuebner @siddu0660 FYI
Currently open PRs:
- https://github.com/llvm/llvm-project/pull/167125
- https://github.com/llvm/llvm-project/pull/167945
- https://github.com/llvm/llvm-project/pull/167948
I'll also add the prefetch builtins.
@Thibault-Monnier Can you comment here on the groups in my table that you have implemented in the PR that I asked you to split up for review?
@andykaylor I am working on:
undefvec_extvinsert, shuffle, blend , perm
Hey @andykaylor, where do the _mm_getcsr and _mm_setcsr builtins fall into in your list?
Hey @andykaylor, where do the
_mm_getcsrand_mm_setcsrbuiltins fall into in your list?
@Thibault-Monnier I left those out of the table because they were already in your PR. I was probably a bit inconsistent in how I handled that, and you added more builtins to the PR while I was creating this issue, I think. Basically, I would like to avoid anyone working on the pieces that you've already prepared.
Hi @andykaylor, I am interested in this work, could I try working on lzcnt, tzcnt ?
hi, @andykaylor, can i work with rdtsc, rdtscp?
hi, @andykaylor, I'm interested in CIR, can I work on vec_set?
hello, can i take gather and scatter ?
hello, @andykaylor , I would like to take masked load/store!
i'm failing an unrelated undef builtin just by including #include <immintrin.h> and having this as the clang command
error:
# | /Users/jjasmine/Developer/igalia/llvm-project/build/lib/clang/22/include/avxintrin.h:3620:18: error: ClangIR code gen Not Yet Implemented: unimplemented X86 builtin call: __builtin_ia32_undef256
# | 3620 | return (__m256)__builtin_ia32_undef256();
test case:
// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s -triple=x86_64-unknown-linux -target-feature +avx512f -target-feature +avx512vl -fclangir -emit-cir -o %t.cir -Wall -Werror -Wsign-conversion
#include <immintrin.h>
__m256 test_mm512_i64gather_ps(__m512i __index, void const *__addr) {
// CHECK-LABEL: test_mm512_i64gather_ps
// CHECK: @llvm.x86.avx512.mask.gather.qps.512
return _mm512_i64gather_ps(__index, __addr, 2);
}
should i start by implementing undef first?
Hey @badumbatish, I am already working on implementing the undef builtins in #167945. It should be ready and merged soon enough.
It's a fairly simple change, so you may just copy the changes of that PR to the CIRGenBuiltinX86.cpp file locally if you wish. That should be enough.
Hi @andykaylor! I'd like to work on the xsave, xrstor builtins.
Hi, @andykaylor, I will work on convert to mask and compress store
Hi Andy, sorry for the delay! Are there any other open tests