summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/mir
AgeCommit message (Collapse)AuthorLines
2024-03-14Rollup merge of #122212 - erikdesjardins:byval-align2, r=wesleywiserMatthias Krüger-23/+39
Copy byval argument to alloca if alignment is insufficient Fixes #122211 "Ignore whitespace" recommended.
2024-03-14Rollup merge of #122287 - RalfJung:simd-static-assert, r=pnkfelixMatthias Krüger-4/+5
add test ensuring simd codegen checks don't run when a static assertion failed stdarch relies on this to ensure that SIMD indices are in bounds. I would love to know why this works, but I can't figure out where codegen decides to not codegen a function if a required-const does not evaluate. `@oli-obk` `@bjorn3` do you have any idea?
2024-03-13Auto merge of #121421 - saethlin:smarter-mono, r=oli-obkbors-1/+20
Avoid lowering code under dead SwitchInt targets The objective of this PR is to detect and eliminate code which is guarded by an `if false`, even if that `false` is a constant which is not known until monomorphization, or is `intrinsics::debug_assertions()`. The effect of this is that we generate no LLVM IR the standard library's unsafe preconditions, when they are compiled in a build where they should be immediately optimized out. This mono-time optimization ensures that builds which disable debug assertions do not grow a linkage requirement against `core`, which compiler-builtins currently needs: https://github.com/rust-lang/rust/issues/121552 This revives the codegen side of https://github.com/rust-lang/rust/pull/91222 as planned in https://github.com/rust-lang/rust/issues/120848.
2024-03-13Auto merge of #122220 - saethlin:ppc-can-into-atomicptr, r=oli-obkbors-40/+10
Only generate a ptrtoint in AtomicPtr codegen when absolutely necessary This special case was added in this PR: https://github.com/rust-lang/rust/pull/77611 in response to this error message: ``` Intrinsic has incorrect argument type! void ({}*)* `@llvm.ppc.cfence.p0sl_s` in function rust_oom LLVM ERROR: Broken function found, compilation aborted! [RUSTC-TIMING] std test:false 20.161 error: could not compile `std` ``` But when I tried searching for more information about that intrinsic I found this: https://github.com/llvm/llvm-project/issues/55983 which is a report of someone hitting this same error and a fix was landed in LLVM, 2 years after the above Rust PR.
2024-03-12Avoid lowering code under dead SwitchInt targetsBen Kimock-1/+20
2024-03-12Auto merge of #121282 - saethlin:gep-null-means-no-provenance, r=scottmcmbors-2/+2
Lower transmutes from int to pointer type as gep on null I thought of this while looking at https://github.com/rust-lang/rust/pull/121242. See that PR's description for why this lowering is preferable. The UI test that's being changed here crashes without changing the transmutes into casts. Based on that, this PR should not be merged without a crater build-and-test run.
2024-03-11Lower transmutes from int to pointer type as gep on nullBen Kimock-2/+2
2024-03-11Rollup merge of #121438 - coolreader18:wasm32-panic-unwind, r=cuviperJubilee-1/+1
std support for wasm32 panic=unwind Tracking issue: #118168 This adds std support for `-Cpanic=unwind` on wasm, and with it slightly more fleshed out rustc support. Now, the stable default is still panic=abort without exception-handling, but if you `-Zbuild-std` with `RUSTFLAGS=-Cpanic=unwind`, you get wasm exception-handling try/catch blocks in the binary: ```rust #[no_mangle] pub fn foo_bar(x: bool) -> *mut u8 { let s = Box::<str>::from("hello"); maybe_panic(x); Box::into_raw(s).cast() } #[inline(never)] #[no_mangle] fn maybe_panic(x: bool) { if x { panic!("AAAAA"); } } ``` ```wat ;; snip... (try $label$5 (do (call $maybe_panic (local.get $0) ) (br $label$1) ) (catch_all (global.set $__stack_pointer (local.get $1) ) (call $__rust_dealloc (local.get $2) (i32.const 5) (i32.const 1) ) (rethrow $label$5) ) ) ;; snip... ```
2024-03-11copy byval argument to alloca if alignment is insufficientErik Desjardins-23/+39
2024-03-10add comments explaining where post-mono const eval errors abort compilationRalf Jung-4/+5
2024-03-09Sink ptrtoint for RMW ops on pointers to cg_llvmBen Kimock-40/+10
2024-03-08Distinguish between library and lang UB in assert_unsafe_preconditionBen Kimock-1/+2
2024-03-08Rollup merge of #119365 - nbdd0121:asm-goto, r=AmanieuMatthias Krüger-7/+33
Add asm goto support to `asm!` Tracking issue: #119364 This PR implements asm-goto support, using the syntax described in "future possibilities" section of [RFC2873](https://rust-lang.github.io/rfcs/2873-inline-asm.html#asm-goto). Currently I have only implemented the `label` part, not the `fallthrough` part (i.e. fallthrough is implicit). This doesn't reduce the expressive though, since you can use label-break to get arbitrary control flow or simply set a value and rely on jump threading optimisation to get the desired control flow. I can add that later if deemed necessary. r? ``@Amanieu`` cc ``@ojeda``
2024-03-08Auto merge of #122048 - erikdesjardins:inbounds, r=oli-obkbors-6/+1
Use GEP inbounds for ZST and DST field offsets ZST field offsets have been non-`inbounds` since I made [this old layout change](https://github.com/rust-lang/rust/pull/73453/files#diff-160634de1c336f2cf325ff95b312777326f1ab29fec9b9b21d5ee9aae215ecf5). Before that, they would have been `inbounds` due to using `struct_gep`. Using `inbounds` for ZSTs likely doesn't matter for performance, but I'd like to remove the special case. DST field offsets have been non-`inbounds` since the alignment-aware DST field offset computation was first [implemented](https://github.com/erikdesjardins/rust/commit/a2557d472e570559caf18d9b042cd941f5002398#diff-04fd352da30ca186fe0bb71cc81a503d1eb8a02ca17a3769e1b95981cd20964aR1188) in 1.6 (back then `GEPi()` would be used for `inbounds`), but I don't think there was any reason for it. Split out from #121577 / #121665. r? `@oli-obk` cc `@RalfJung` -- is there some weird situation where field offsets can't be `inbounds`? Note that it's fine for `inbounds` offsets to be one-past-the-end, so it's okay even if there's a ZST as the last field in the layout: > The base pointer has an in bounds address of an allocated object, which means that it points into an allocated object, or to its end. [(link)](https://llvm.org/docs/LangRef.html#getelementptr-instruction) For https://github.com/rust-lang/unsafe-code-guidelines/issues/93, zero-offset GEP is (now) always `inbounds`: > Note that getelementptr with all-zero indices is always considered to be inbounds, even if the base pointer does not point to an allocated object. [(link)](https://llvm.org/docs/LangRef.html#getelementptr-instruction)
2024-03-06Rollup merge of #122051 - erikdesjardins:cleanup, r=nikicMatthias Krüger-2/+1
cleanup: remove zero-offset GEP This GEP would've been used to change the pointer type in the past, but after opaque pointers it's a no-op. I missed removing this in #105545. Split out from #121577.
2024-03-05remove all-zero GEPErik Desjardins-2/+1
This always produces zero offset, regardless of what the struct layout is. Originally, this may have been necessary in order to change the pointer type, but with opaque pointers, it is no longer necessary.
2024-03-05Rollup merge of #122028 - oli-obk:drop_in_place_leftovers, r=compiler-errorsMatthias Krüger-1/+1
Remove some dead code drop_in_place has been a lang item, not an intrinsic, for forever
2024-03-05Remove some dead codeOli Scherer-1/+1
drop_in_place has been a lang item, not an intrinsic, for forever
2024-03-05only set noalias on Box with the global allocatorRalf Jung-0/+1
2024-03-04Avoid some boolean argument footgunsOli Scherer-10/+26
2024-03-04Add a scheme for moving away from `extern "rust-intrinsic"` entirelyOli Scherer-1/+10
2024-03-04Return a struct from `query intrinsic` to be able to add another field in ↵Oli Scherer-6/+6
the next commit
2024-03-04use GEP inbounds for ZST and DST field offsetsErik Desjardins-6/+1
For the former, it's fine for `inbounds` offsets to be one-past-the-end, so it's okay even if the ZST is the last field in the layout: > The base pointer has an in bounds address of an allocated object, > which means that it points into an allocated object, or to its end. https://llvm.org/docs/LangRef.html#getelementptr-instruction For the latter, even DST fields must always be inside the layout (or to its end for ZSTs), so using inbounds is also fine there.
2024-03-03Auto merge of #121665 - erikdesjardins:ptradd, r=nikicbors-33/+13
Always generate GEP i8 / ptradd for struct offsets This implements #98615, and goes a bit further to remove `struct_gep` entirely. Upstream LLVM is in the beginning stages of [migrating to `ptradd`](https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699). LLVM 19 will [canonicalize](https://github.com/llvm/llvm-project/pull/68882) all constant-offset GEPs to i8, which has roughly the same effect as this change. Fixes #121719. Split out from #121577. r? `@nikic`
2024-02-28Add `f16` and `f128` to `rustc_type_ir::FloatTy` and `rustc_abi::Primitive`Trevor Gross-3/+5
Make changes necessary to support these types in the compiler.
2024-02-27use non-inbounds GEP for ZSTs, add fixmesErik Desjardins-0/+5
2024-02-26introduce and use ptradd/inbounds_ptradd instead of gepErik Desjardins-5/+4
2024-02-26always use gep inbounds i8 (ptradd) for field offsetsErik Desjardins-29/+5
2024-02-24Add assertions and clarify asm-goto with noreturnGary Guo-0/+1
2024-02-24Implement asm goto for LLVM and GCC backendGary Guo-8/+30
2024-02-24Implement asm goto in MIR and MIR loweringGary Guo-0/+3
2024-02-24Change InlineAsm to allow multiple targets insteadGary Guo-2/+2
2024-02-23Use `br` instead of conditional when branching on constantclubby789-5/+13
2024-02-22Fix llvm hangNoa-1/+1
2024-02-22Auto merge of #121225 - RalfJung:simd-extract-insert-const-idx, ↵bors-2/+1
r=oli-obk,Amanieu require simd_insert, simd_extract indices to be constants As discussed in https://github.com/rust-lang/rust/issues/77477 (see in particular [here](https://github.com/rust-lang/rust/issues/77477#issuecomment-703149102)). This PR doesn't touch codegen yet -- the first step is to ensure that the indices are always constants; the second step is to then make use of this fact in backends. Blocked on https://github.com/rust-lang/stdarch/pull/1530 propagating to the rustc repo.
2024-02-20Add "algebraic" versions of the fast-math intrinsicsBen Kimock-0/+32
2024-02-20require simd_insert, simd_extract indices to be constantsRalf Jung-2/+1
2024-02-12Give const_deallocate a default bodyOli Scherer-5/+0
2024-02-12Teach llvm backend how to fall back to default bodiesOli Scherer-50/+45
2024-02-12Create ret_dest as late as possible in all code pathsOli Scherer-13/+19
2024-02-12Do the entire ReturnDest computation within make_return_destOli Scherer-6/+12
2024-02-12Implement intrinsics with fallback bodiesOli Scherer-1/+1
2024-02-08Add a new debug_assertions instrinsic (compiler)Ben Kimock-4/+10
And in clippy
2024-02-08Don't lower assume in unoptimized buildsBen Kimock-2/+5
2024-01-22Do not normalize closure signature when building FnOnce shimMichael Goulet-1/+0
2024-01-15compiler: Lower fn call arg spans down to MIRMartin Nordholts-8/+13
To enable improved accuracy of diagnostics in upcoming commits.
2024-01-09Rollup merge of #118903 - azhogin:azhogin/skip_second_stmt_debuginfo.rs, ↵Matthias Krüger-11/+6
r=petrochenkov Improved support of collapse_debuginfo attribute for macros. Added walk_chain_collapsed function to consider collapse_debuginfo attribute in parent macros in call chain. Fixed collapse_debuginfo attribute processing for cranelift (there was if/else branches error swap). cc https://github.com/rust-lang/rust/issues/100758
2024-01-08Improved support of collapse_debuginfo attribute for macros.Andrew Zhogin-11/+6
2024-01-05Auto merge of #118991 - nikic:scalar-pair, r=nagisabors-21/+13
Separate immediate and in-memory ScalarPair representation Currently, we assume that ScalarPair is always represented using a two-element struct, both as an immediate value and when stored in memory. This currently works fairly well, but runs into problems with https://github.com/rust-lang/rust/pull/116672, where a ScalarPair involving an i128 type can no longer be represented as a two-element struct in memory. For example, the tuple `(i32, i128)` needs to be represented in-memory as `{ i32, [3 x i32], i128 }` to satisfy alignment requirements. Using `{ i32, i128 }` instead will result in the second element being stored at the wrong offset (prior to LLVM 18). Resolve this issue by no longer requiring that the immediate and in-memory type for ScalarPair are the same. The in-memory type will now look the same as for normal struct types (and will include padding filler and similar), while the immediate type stays a simple two-element struct type. This also means that booleans in immediate ScalarPair are now represented as i1 rather than i8, just like we do everywhere else. The core change here is to llvm_type (which now treats ScalarPair as a normal struct) and immediate_llvm_type (which returns the two-element struct that llvm_type used to produce). The rest is fixing things up to no longer assume these are the same. In particular, this switches places that try to get pointers to the ScalarPair elements to use byte-geps instead of struct-geps.
2024-01-02Address review commentsNikita Popov-7/+5