Closed
Description
https://play.rust-lang.org/?gist=7555908f8176d50b10cd06a4a5dba401&version=nightly&mode=release
Given code like:
#![crate_type = "lib"]
use std::sync::atomic::*;
static A: AtomicUsize = ATOMIC_USIZE_INIT;
pub unsafe fn foo() {
A.load(Ordering::SeqCst);
}
the generated LLVM IR is:
; ModuleID = 'playground0-99a4292f5ecb26a54a3204a5a67308ec.rs'
source_filename = "playground0-99a4292f5ecb26a54a3204a5a67308ec.rs"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@_ZN10playground1A17h5c8cc46ff3ae8084E = internal unnamed_addr constant <{ [8 x i8] }> zeroinitializer, align 8
; playground::foo
; Function Attrs: norecurse nounwind uwtable
define void @_ZN10playground3foo17h1cb1a21ad3c6e213E() unnamed_addr #0 {
start:
%0 = load atomic i64, i64* bitcast (<{ [8 x i8] }>* @_ZN10playground1A17h5c8cc46ff3ae8084E to i64*) seq_cst, align 8
ret void
}
attributes #0 = { norecurse nounwind uwtable "probe-stack"="__rust_probestack" }
and unfortunately our atomic load wasn't optimized away!
I believe this is a regression from stable to beta due to the way that miri defines statics (looks like LLVM doesn't recognize the bitcast) cc @oli-obk
Metadata
Metadata
Assignees
Labels
Area: Code generationArea: Constant evaluation, covers all const contexts (static, const fn, ...)Category: An issue proposing an enhancement or a PR with one.Issue: Problems and improvements with respect to performance of generated code.Medium priorityRelevant to the compiler team, which will review and decide on the PR/issue.Working group: LLVM backend code generationPerformance or correctness regression from one stable version to another.