about summary refs log tree commit diff
path: root/src/test/codegen
AgeCommit message (Collapse)AuthorLines
2022-08-20Rollup merge of #100693 - scottmcm:new-llvm15-nops, r=Mark-SimulacrumMatthias Krüger-0/+54
Add LLVM15-specific codegen test for `try`/`?`s that now optimize away These still generated a bunch of code back in Rust 1.63 (<https://rust.godbolt.org/z/z31P8h6rz>), but with LLVM 15 merged they no longer do 🎉
2022-08-17Add LLVM15-specific codegen test for `try`/`?`s that now optimize awayScott McMurray-0/+54
These still generated a bunch of code back in Rust 1.63 (<https://rust.godbolt.org/z/z31P8h6rz>), but with LLVM 15 merged they no longer do :tada:
2022-08-16Rollup merge of #100460 - cuviper:drop-llvm-12, r=nagisaMatthias Krüger-87/+1
Update the minimum external LLVM to 13 With this change, we'll have stable support for LLVM 13 through 15 (pending release). For reference, the previous increase to LLVM 12 was #90175. r? `@nagisa`
2022-08-16Rollup merge of #100384 - ridwanabdillahi:instr_profile_output, r=wesleywiserMatthias Krüger-0/+17
Add support for generating unique profraw files by default when using `-C instrument-coverage` Currently, enabling the rustc flag `-C instrument-coverage` instruments the given crate and by default uses the naming scheme `default.profraw` for any instrumented profile files generated during the execution of a binary linked against this crate. This leads to multiple binaries being executed overwriting one another and causing only the last executable run to contain actual coverage results. This can be overridden by manually setting the environment variable `LLVM_PROFILE_FILE` to use a unique naming scheme. This PR adds a change to add support for a reasonable default for rustc to use when enabling coverage instrumentation similar to how the Rust compiler treats generating these same `profraw` files when PGO is enabled. The new naming scheme is set to `default_%m_%p.profraw` to ensure the uniqueness of each file being generated using [LLVMs special pattern strings](https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#running-the-instrumented-program). Today the compiler sets the default for PGO `profraw` files to `default_%m.profraw` to ensure a unique file for each run. The same can be done for the instrumented profile files generated via the `-C instrument-coverage` flag as well which LLVM has API support for. Linked Issue: https://github.com/rust-lang/rust/issues/100381 r? `@wesleywiser`
2022-08-14Update the minimum external LLVM to 13Josh Stone-87/+1
2022-08-12[debuginfo] Update codegen tests for new cpp-like enum debuginfo encoding.Michael Woerister-9/+12
2022-08-11Add support for generating unique *.profraw files by default when using the ↵ridwanabdillahi-0/+17
`-C instrument-coverage` flag. Respond to PR comments.
2022-08-10Auto merge of #99174 - scottmcm:reoptimize-layout-array, r=joshtriplettbors-0/+31
Reoptimize layout array This way it's one check instead of two, so hopefully (cc #99117) it'll be simpler for rustc perf too 🤞 Quick demonstration: ```rust pub fn demo(n: usize) -> Option<Layout> { Layout::array::<i32>(n).ok() } ``` Nightly: <https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=e97bf33508aa03f38968101cdeb5322d> ```nasm mov rax, rdi mov ecx, 4 mul rcx seto cl movabs rdx, 9223372036854775805 xor esi, esi cmp rax, rdx setb sil shl rsi, 2 xor edx, edx test cl, cl cmove rdx, rsi ret ``` This PR (note no `mul`, in addition to being much shorter): ```nasm xor edx, edx lea rax, [4*rcx] shr rcx, 61 sete dl shl rdx, 2 ret ``` This is built atop `@CAD97` 's #99136; the new changes are cb8aba66ef6a0e17f08a0574e4820653e31b45a0. I added a bunch more tests for `Layout::from_size_align` and `Layout::array` too.
2022-08-05Auto merge of #100035 - workingjubilee:merge-functions, r=nikicbors-2/+4
Enable function merging when opt is for size It is, of course, natural to want to merge aliasing functions when optimizing for code size, since that can eliminate several bytes. And an exhaustive match helps make the code less brittle. Closes #98215.
2022-08-05Enable function merging when opt is for sizeJubilee Young-2/+4
It is, of course, natural to want to merge aliasing functions when optimizing for code size, since that can eliminate several bytes. And an exhaustive match helps make the code less brittle.
2022-07-27Make CFI tests opaque pointers compatibleNikita Popov-7/+6
2022-07-27Remove outdated rustc_allocator testNikita Popov-7/+0
This attribute now does more than just place noalias on the return, and has specific requirements for the signature. Drop the test entirely, as we already check __rust_alloc attributes in other codegen tests.
2022-07-27Update codegen test for opaque pointersNikita Popov-8/+8
2022-07-26codegen: use new {re,de,}allocator annotations in llvmAugie Fackler-0/+183
This obviates the patch that teaches LLVM internals about _rust_{re,de}alloc functions by putting annotations directly in the IR for the optimizer. The sole test change is required to anchor FileCheck to the body of the `box_uninitialized` method, so it doesn't see the `allocalign` on `__rust_alloc` and get mad about the string `alloca` showing up. Since I was there anyway, I added some checks on the attributes to prove the right attributes got set. While we're here, we also emit allocator attributes on __rust_alloc_zeroed. This should allow LLVM to perform more optimizations for zeroed blocks, and probably fixes #90032. [This comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157) mentions "weird UB-like behaviour with bitvec iterators in rustc_data_structures" so we may need to back this change out if things go wrong. The new test cases require LLVM 15, so we copy them into LLVM 14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-25Auto merge of #97581 - ↵bors-12/+124
AngelicosPhosphoros:improve_calloc_check_in_vec_macro_for_tuples, r=Mark-Simulacrum Support vec zero-alloc optimization for tuples and byte arrays * Implement IsZero trait for tuples up to 8 IsZero elements; * Implement IsZero for u8/i8, leading to implementation of it for arrays of them too; * Add more codegen tests for this optimization. * Lower size of array for IsZero trait because it fails to inline checks
2022-07-24Support vec zero-alloc optimization for tuples and byte arraysAngelicosPhosphoros-12/+124
* Implement IsZero trait for tuples up to 8 IsZero elements; * Implement IsZero for u8/i8, leading to implementation of it for arrays of them too; * Add more codegen tests for this optimization. * Lower size of array for IsZero trait because it fails to inline checks
2022-07-24Auto merge of #99409 - tmiasko:atomic-tests, r=m-ou-sebors-1/+109
Test codegen of atomic compare-exchange with additional memory orderings * Add a test for atomic operations introduced in #97423 & #98383. * Add a test for fallback code generation strategy used on LLVM 12 introduced in #98385. Use a separate test case instead of a revision system since test will be gone once LLVM 12 is no longer supported.
2022-07-24Auto merge of #95548 - rcvalle:rust-cfi-2, r=nagisabors-39/+608
Add fine-grained LLVM CFI support to the Rust compiler This PR improves the LLVM Control Flow Integrity (CFI) support in the Rust compiler by providing forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue https://github.com/rust-lang/rust/issues/89653). LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto). Thank you again, `@eddyb,` `@nagisa,` `@pcc,` and `@tmiasko` for all the help!
2022-07-23Auto merge of #98208 - ivanloz:master, r=nagisabors-0/+17
Add support for LLVM ShadowCallStack. LLVMs ShadowCallStack provides backward edge control flow integrity protection by using a separate shadow stack to store and retrieve a function's return address. LLVM currently only supports this for AArch64 targets. The x18 register is used to hold the pointer to the shadow stack, and therefore this only works on ABIs which reserve x18. Further details are available in the [LLVM ShadowCallStack](https://clang.llvm.org/docs/ShadowCallStack.html) docs. # Usage `-Zsanitizer=shadow-call-stack` # Comments/Caveats * Currently only enabled for the aarch64-linux-android target * Requires the platform to define a runtime to initialize the shadow stack, see the [LLVM docs](https://clang.llvm.org/docs/ShadowCallStack.html) for more detail.
2022-07-23Add fine-grained LLVM CFI support to the Rust compilerRamon de C Valle-39/+608
This commit improves the LLVM Control Flow Integrity (CFI) support in the Rust compiler by providing forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653). LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto).
2022-07-22do not mark interior mutable shared refs as dereferenceableRalf Jung-1/+19
2022-07-22Auto merge of #99491 - workingjubilee:sync-psimd, r=workingjubileebors-1/+1
Sync in portable-simd subtree r? `@ghost`
2022-07-20Introduce core::simd trait imports in testsJubilee Young-1/+1
2022-07-20Test codegen of atomic compare-exchange with additional memory orderingsTomasz Miąsko-1/+109
* Add a test for atomic operations introduced in #97423 & #98383. * Add a test for fallback code generation strategy used on LLVM 12 introduced in #98385. Use a separate test case instead of a revision system since test will be gone once LLVM 12 is no longer supported.
2022-07-20Add ShadowCallStack SupportIvan Lozano-0/+17
Adds support for the LLVM ShadowCallStack sanitizer.
2022-07-20Rollup merge of #99436 - Nilstrieb:toggle-box-noalias, r=fee1-deadDylan DPC-0/+16
Add flag to configure `noalias` on `Box<T>` The aliasing rules of `Box<T>` are still not decided, but currently, `Box<T>` is unique and gets `noalias`. To aid making an informed decision about the future of `Box<T>`, this PR adds a flag `-Zbox-noalias` to configure `noalias` for `Box<T>` (for example, for benchmarking). The same flag already exists for `&mut T` `noalias`, where it was added because it was the problem of various miscompilations in LLVM. For more information, see rust-lang/unsafe-code-guidelines#326
2022-07-19Add flag to configure `noalias` on `Box<T>`nils-0/+16
To aid making an informed decision about the aliasing rules of box, give users an option to remove `noalias` from box.
2022-07-18Rollup merge of #98998 - ↵Dylan DPC-1/+1
workingjubilee:naked-means-no-clothes-enforcement-technology, r=Amanieu Remove branch target prologues from `#[naked] fn` This patch hacks around rust-lang/rust#98768 for now via injecting appropriate attributes into the LLVMIR we emit for naked functions. I intend to pursue this upstream so that these attributes can be removed in general, but it's slow going wading through C++ for me.
2022-07-13Re-optimize `Layout::array`Scott McMurray-0/+31
This way it's one check instead of two, so hopefully it'll be better Nightly: ``` layout_array_i32: movq %rdi, %rax movl $4, %ecx mulq %rcx jo .LBB1_2 movabsq $9223372036854775805, %rcx cmpq %rcx, %rax jae .LBB1_2 movl $4, %edx retq .LBB1_2: … ``` This PR: ``` movq %rcx, %rax shrq $61, %rax jne .LBB2_1 shlq $2, %rcx movl $4, %edx movq %rcx, %rax retq .LBB2_1: … ```
2022-07-08Support unstable moves via stable in unstable itemsJane Lusby-0/+1
2022-07-08Auto merge of #98758 - nnethercote:more-derive-output-improvements, ↵bors-1/+1
r=Mark-Simulacrum More derive output improvements This PR includes: - Some test improvements. - Some cosmetic changes to derive output that make the code look more like what a human would write. - Some more fundamental improvements to `cmp` and `partial_cmp` generation. r? `@Mark-Simulacrum`
2022-07-07Bless MSVC debuginfo.Camille GILLOT-2/+2
2022-07-07Bless codegen test.Camille GILLOT-2/+2
2022-07-06Stop emitting CET prologues for naked functionsJubilee Young-1/+1
We can apply nocf_check as a hack for now.
2022-07-05Rollup merge of #98920 - krasimirgg:llvm-15-issue-37945, r=nikicMatthias Krüger-2/+6
adapt issue-37945 codegen test to accept any order of ops Adapt this test to accept `icmp` operands in any order as a follow-up to https://github.com/rust-lang/rust/commit/cbbf06b0cd39dc93033568f1e65f5363cbbdebcd#commitcomment-77670922.
2022-07-05adapt issue-37945 codegen test to accept any order of opsKrasimir Georgiev-2/+6
2022-07-05Auto merge of #96862 - oli-obk:enum_cast_mir, r=RalfJungbors-7/+14
Change enum->int casts to not go through MIR casts. follow-up to https://github.com/rust-lang/rust/pull/96814 this simplifies all backends and even gives LLVM more information about the return value of `Rvalue::Discriminant`, enabling optimizations in more cases.
2022-07-04Avoid unnecessary 1-tuples in derived code.Nicholas Nethercote-1/+1
2022-07-01Amend codegen test.Camille GILLOT-22/+24
2022-06-30Auto merge of #98377 - davidv1992:add-lifetimes-to-argument-temporaries, ↵bors-0/+27
r=oli-obk Added llvm lifetime annotations to function call argument temporaries. The goal of this change is to ensure that llvm will do stack slot optimization on these temporaries. This ensures that in code like: ```rust const A: [u8; 1024] = [0; 1024]; fn copy_const() { f(A); f(A); } ``` we only use 1024 bytes of stack space, instead of 2048 bytes. I am new to developing for the rust compiler, and as such not entirely sure, but I believe this should be sufficient to close #98156. Also, this does not contain a test case to ensure this keeps working, primarily because I am not sure how to go about testing this. I would love some suggestions as to how that could be approached.
2022-06-30Change enum->int casts to not go through MIR casts.Oli Scherer-7/+14
Instead we generate a discriminant rvalue and cast the result of that.
2022-06-25Added test for const arg lifetimes suggested by erikdesjardins.David Venhoek-0/+27
2022-06-25Auto merge of #96820 - r-raymond:master, r=cuviperbors-0/+14
Make RwLockReadGuard covariant Hi, first time contributor here, if anything is not as expected, please let me know. `RwLockReadGoard`'s type constructor is invariant. Since it behaves like a smart pointer to an immutable reference, there is no reason that it should not be covariant. Take e.g. ``` fn test_read_guard_covariance() { fn do_stuff<'a>(_: RwLockReadGuard<'_, &'a i32>, _: &'a i32) {} let j: i32 = 5; let lock = RwLock::new(&j); { let i = 6; do_stuff(lock.read().unwrap(), &i); } drop(lock); } ``` where the compiler complains that &i doesn't live long enough. If `RwLockReadGuard` is covariant, then the above code is accepted because the lifetime can be shorter than `'a`. In order for `RwLockReadGuard` to be covariant, it can't contain a full reference to the `RwLock`, which can never be covariant (because it exposes a mutable reference to the underlying data structure). By reducing the data structure to the required pieces of `RwLock`, the rest falls in place. If there is a better way to do a test that tests successful compilation, please let me know. Fixes #80392
2022-06-21Auto merge of #95576 - DrMeepster:box_erasure, r=oli-obkbors-20/+20
Remove dereferencing of Box from codegen Through #94043, #94414, #94873, and #95328, I've been fixing issues caused by Box being treated like a pointer when it is not a pointer. However, these PRs just introduced special cases for Box. This PR removes those special cases and instead transforms a deref of Box into a deref of the pointer it contains. Hopefully, this is the end of the Box<T, A> ICEs.
2022-06-20UnsafeCell -> RwLockRobin Raymond-4/+3
2022-06-19Make sure we don't match noalias in later linesRobin Raymond-0/+1
2022-06-19Add test to verify noalias is not being addedRobin Raymond-0/+14
2022-06-15remove box derefs from codgenDrMeepster-20/+20
2022-06-15Rollup merge of #98078 - erikdesjardins:uncheckedsize, r=petrochenkovYuki Okushi-0/+29
Use unchecked mul to compute slice sizes This allows LLVM to realize that `slice.len() > 0` iff `slice.len() * size_of::<T>() > 0`, allowing a branch on the latter to be folded into the former when dropping vecs and boxed slices, in some cases. Fixes (partially) #96497
2022-06-14use unchecked mul to compute slice sizesErik Desjardins-0/+29
...since slice sizes can't signed wrap see https://doc.rust-lang.org/std/slice/fn.from_raw_parts.html > The total size len * mem::size_of::<T>() of the slice must be no larger than isize::MAX.