about summary refs log tree commit diff
path: root/tests/codegen/intrinsics
AgeCommit message (Collapse)AuthorLines
2025-07-22Rename `tests/codegen` into `tests/codegen-llvm`Guillaume Gomez-1877/+0
2025-07-10Add `BuilderMethods::unreachable_nonterminator`Scott McMurray-21/+20
So places that need `unreachable` but in the middle of a basic block can call that instead of figuring out the best way to do it.
2025-07-09Make UB transmutes really UB in LLVMScott McMurray-9/+13
Ralf suggested in <https://github.com/rust-lang/rust/pull/143410#discussion_r2184928123> that UB transmutes shouldn't be trapping, which happened for the one path that PR was changing, but there's another path as well, so this PR changes that other path to match.
2025-07-04Address PR feedbackScott McMurray-7/+7
2025-07-03Block SIMD in transmute_immediate; delete `OperandValueKind`Scott McMurray-4/+7
See conversation in <https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Is.20transmuting.20a.20.60T.60.20to.20.60Tx1.60.20.28one-element.20SIMD.20vector.29.20UB.3F/near/526262799>.
2025-05-01Stabilize `select_unpredictable`Amanieu d'Antras-1/+0
FCP completed in tracking issue #133962.
2025-04-13Move `select_unpredictable` to the `hint` moduleAmanieu d'Antras-4/+4
2025-04-06update/bless testsBennet Bleßmann-3/+2
2025-04-05Update the minimum external LLVM to 19Josh Stone-8/+4
2025-03-24Auto merge of #133984 - DaniPopes:scmp-ucmp, r=scottmcmbors-22/+5
Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsics Lowers `mir::BinOp::Cmp` (`three_way_compare` intrinsic) to the corresponding LLVM `llvm.{s,u}cmp.i8.*` intrinsics. These are the intrinsics mentioned in https://github.com/rust-lang/rust/pull/118310, which are now available in LLVM 19. I couldn't find any follow-up PRs/discussions about this, please let me know if I missed something. r? `@scottmcm`
2025-03-12Don't `alloca` just to look at a discriminantScott McMurray-2/+2
Today we're making LLVM do a bunch of extra work for every enum you match on, even trivial stuff like `Option<bool>`. Let's not.
2025-03-09Auto merge of #137513 - scottmcm:identity-transmute, r=saethlinbors-0/+25
Don't re-`assume` in `transmute`s that don't change niches I noticed in nightly 2025-02-21 that `transmute` is emitting way more `assume`s than necessary for newtypes. For example, the three transmutes in <https://rust.godbolt.org/z/fW1KaTc4o> emits ```rust define noundef range(i32 1, 0) i32 `@repeatedly_transparent_transmute(i32` noundef range(i32 1, 0) %_1) unnamed_addr { start: %0 = sub i32 %_1, 1 %1 = icmp ule i32 %0, -2 call void `@llvm.assume(i1` %1) %2 = sub i32 %_1, 1 %3 = icmp ule i32 %2, -2 call void `@llvm.assume(i1` %3) %4 = sub i32 %_1, 1 %5 = icmp ule i32 %4, -2 call void `@llvm.assume(i1` %5) %6 = sub i32 %_1, 1 %7 = icmp ule i32 %6, -2 call void `@llvm.assume(i1` %7) %8 = sub i32 %_1, 1 %9 = icmp ule i32 %8, -2 call void `@llvm.assume(i1` %9) %10 = sub i32 %_1, 1 %11 = icmp ule i32 %10, -2 call void `@llvm.assume(i1` %11) ret i32 %_1 } ``` But those are all just newtypes that don't change size or niches, so none of it's needed. After this PR it's down to just ```rust define noundef range(i32 1, 0) i32 `@repeatedly_transparent_transmute(i32` noundef range(i32 1, 0) %_1) unnamed_addr { start: ret i32 %_1 } ``` because none of those `assume`s in the original actually did anything. (Transmuting to something with a difference niche, though, still has the assumes -- the other tests continue to pass checking that.)
2025-03-06Use `trunc nuw`+`br` for 0/1 branches even in optimized buildsScott McMurray-1/+2
Rather than needing to use `switch` for them to include the `unreachable` arm
2025-03-06Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsicsDaniPopes-22/+5
Lowers `mir::BinOp::Cmp` (`three_way_compare` intrinsic) to the corresponding LLVM `llvm.{s,u}cmp.i8.*` intrinsics, added in LLVM 19.
2025-02-24tests: use minicore moreDavid Wood-7/+3
minicore makes it much easier to add new language items to all of the existing `no_core` tests.
2025-02-23Don't re-`assume` in `transmute`s that don't change nichesScott McMurray-0/+25
2025-02-24Auto merge of #137271 - nikic:gep-nuw-2, r=scottmcmbors-2/+2
Emit getelementptr inbounds nuw for pointer::add() Lower pointer::add (via intrinsic::offset with unsigned offset) to getelementptr inbounds nuw on LLVM versions that support it. This lets LLVM make use of the pre-condition that the offset addition does not wrap in an unsigned sense. Together with inbounds, this also implies that the offset is non-negative. Fixes https://github.com/rust-lang/rust/issues/137217.
2025-02-23Rollup merge of #136543 - RalfJung:round-ties-even, r=tgross35Trevor Gross-18/+0
intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even intrinsic LLVM has three intrinsics here that all do the same thing (when used in the default FP environment). There's no reason Rust needs to copy that historically-grown mess -- let's just have one intrinsic and leave it up to the LLVM backend to decide how to lower that. Suggested by `@hanna-kruppe` in https://github.com/rust-lang/rust/issues/136459; Cc `@tgross35` try-job: test-various
2025-02-19Emit `trunc nuw` for unchecked shifts and `to_immediate_scalar`Scott McMurray-5/+8
- For shifts this shrinks the IR by no longer needing an `assume` while still providing the UB information - Having this on the `i8`→`i1` truncations will hopefully help with some places that have to load `i8`s or pass those in LLVM structs without range information
2025-02-19Emit getelementptr inbounds nuw for pointer::add()Nikita Popov-2/+2
2025-02-19Auto merge of #135408 - RalfJung:x86-sse2, r=workingjubileebors-9/+0
x86: use SSE2 to pass float and SIMD types This builds on the new X86Sse2 ABI landed in https://github.com/rust-lang/rust/pull/137037 to actually make it a separate ABI from the default x86 ABI, and use SSE2 registers. Specifically, we use it in two ways: to return `f64` values in a register rather than by-ptr, and to pass vectors of size up to 128bit in a register (or, well, whatever LLVM does when passing `<4 x float>` by-val, I don't actually know if this ends up in a register). Cc `@workingjubilee` Fixes #133611 try-job: aarch64-apple try-job: aarch64-gnu try-job: aarch64-gnu-debug try-job: test-various try-job: x86_64-gnu-nopt try-job: dist-i586-gnu-i586-i686-musl try-job: x86_64-msvc-1
2025-02-18x86-sse2 ABI: use SSE registers for floats and SIMDRalf Jung-9/+0
2025-02-18Auto merge of #133852 - x17jiri:cold_path, r=saethlinbors-0/+123
improve cold_path() #120370 added a new instrinsic `cold_path()` and used it to fix `likely` and `unlikely` However, in order to limit scope, the information about cold code paths is only used in 2-target switch instructions. This is sufficient for `likely` and `unlikely`, but limits usefulness of `cold_path` for idiomatic rust. For example, code like this: ``` if let Some(x) = y { ... } ``` may generate 3-target switch: ``` switch y.discriminator: 0 => true branch 1 = > false branch _ => unreachable ``` and therefore marking a branch as cold will have no effect. This PR improves `cold_path()` to work with arbitrary switch instructions. Note that for 2-target switches, we can use `llvm.expect`, but for multiple targets we need to manually emit branch weights. I checked Clang and it also emits weights in this situation. The Clang's weight calculation is more complex that this PR, which I believe is mainly because `switch` in `C/C++` can have multiple cases going to the same target.
2025-02-17improve cold_path()Jiri Bobek-0/+123
2025-02-12`transmute` should also assume non-null pointersScott McMurray-3/+34
Previously it only did integer-ABI things, but this way it does data pointers too. That gives more information in general to the backend, and allows slightly simplifying one of the helpers in slice iterators.
2025-02-11tests/codegen: use -Copt-level=3 instead of -OJubilee Young-12/+12
2025-02-04intrinsics: unify rint, roundeven, nearbyint in a single round_ties_even ↵Ralf Jung-18/+0
intrinsic
2025-02-02Handle the case where the `or disjoint` folds immediately to a constantScott McMurray-1/+11
2025-01-31Override `disjoint_or` in the LLVM backendScott McMurray-0/+20
2025-01-17Update our range `assume`s to the format that LLVM prefersScott McMurray-55/+67
2025-01-05Expand the `select_unpredictable` test for ZSTsTrevor Gross-0/+5
For ZSTs there is no selection that needs to take place, so assert that no `select` statement is emitted.
2025-01-05Merge the intrinsic and user tests for `select_unpredictable`Trevor Gross-1/+33
[1] mentions that having a single test with `-Zmerge-functions=disabled` is preferable to having two separate tests. Apply that to the new `select_unpredicatble` test here. [1]: https://github.com/rust-lang/rust/pull/133964#issuecomment-2569693325
2025-01-03Update carrying_mul_add test to tolerate `nuw`Matthew Maurer-2/+2
LLVM 20 adds nuw to GEP operations in this code, tolerate them.
2024-12-30Auto merge of #134757 - RalfJung:const_swap, r=scottmcmbors-6/+6
stabilize const_swap libs-api FCP passed in https://github.com/rust-lang/rust/issues/83163. However, I only just realized that this actually involves an intrinsic. The intrinsic could be implemented entirely with existing stable const functionality, but we choose to make it a primitive to be able to detect more UB. So nominating for `@rust-lang/lang` to make sure they are aware; I leave it up to them whether they want to FCP this. While at it I also renamed the intrinsic to make the "nonoverlapping" constraint more clear. Fixes #83163
2024-12-27Override `carrying_mul_add` in cg_llvmScott McMurray-0/+137
2024-12-25rename typed_swap → typed_swap_nonoverlappingRalf Jung-6/+6
2024-11-17Likely unlikely fixJiri Bobek-12/+90
2024-10-23Set `signext` or `zeroext` for integer arguments on RISC-VAsuna-4/+2
2024-09-04Don't codegen `expect` in opt-level=0clubby789-1/+1
2024-08-19Don't generate functions with the `rustc_intrinsic_must_be_overridden` attributeDianQK-0/+14
2024-08-12make the codegen test also cover an ill-behaved arch, and add linksRalf Jung-3/+12
2024-08-05nontemporal_store: make sure that the intrinsic is truly just a hintRalf Jung-2/+17
2024-07-30Auto merge of #128250 - Amanieu:select_unpredictable, r=nikicbors-0/+35
Add `select_unpredictable` to force LLVM to use CMOV Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs into branches if it comes from a `select` marked with an `unpredictable` metadata attribute. This PR introduces `core::intrinsics::select_unpredictable` which emits such a `select` and uses it in the implementation of `binary_search_by`.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-3/+2
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28Force LLVM to use CMOV for binary searchAmanieu d'Antras-0/+35
Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs into branches if it comes from a `select` marked with an `unpredictable` metadata attribute. This PR introduces `core::intrinsics::select_unpredictable` which emits such a `select` and uses it in the implementation of `binary_search_by`.
2024-05-31Run rustfmt on `tests/codegen/`.Nicholas Nethercote-15/+12
Except for `simd-intrinsic/`, which has a lot of files containing multiple types like `u8x64` which really are better when hand-formatted. There is a surprising amount of two-space indenting in this directory. Non-trivial changes: - `rustfmt::skip` needed in `debug-column.rs` to preserve meaning of the test. - `rustfmt::skip` used in a few places where hand-formatting read more nicely: `enum/enum-match.rs` - Line number adjustments needed for the expected output of `debug-column.rs` and `coroutine-debug.rs`.
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-0/+36
2024-05-16Fix ICE in non-operand `aggregate_raw_ptr` instrinsic codegenScott McMurray-0/+23
2024-04-24Fix tests and blessGary Guo-1/+0
2024-04-24Auto merge of #122053 - erikdesjardins:alloca, r=nikicbors-8/+8
Stop using LLVM struct types for alloca The alloca type has no semantic meaning, only the size (and alignment, but we specify it explicitly) matter. Using `[N x i8]` is a more direct way to specify that we want `N` bytes, and avoids relying on LLVM's struct layout. It is likely that a future LLVM version will change to an untyped alloca representation. Split out from #121577. r? `@ghost`