@@ -11,7 +11,7 @@ use rustc_hir as hir;
11
11
use rustc_hir:: lang_items:: LangItem ;
12
12
use rustc_index:: bit_set:: BitSet ;
13
13
use rustc_index:: vec:: { Idx , IndexVec } ;
14
- use rustc_session:: { DataTypeKind , FieldInfo , SizeKind , VariantInfo } ;
14
+ use rustc_session:: { config :: OptLevel , DataTypeKind , FieldInfo , SizeKind , VariantInfo } ;
15
15
use rustc_span:: symbol:: { Ident , Symbol } ;
16
16
use rustc_span:: DUMMY_SP ;
17
17
use rustc_target:: abi:: call:: {
@@ -2318,23 +2318,30 @@ where
2318
2318
ty:: Ref ( _, ty, mt) if offset. bytes ( ) == 0 => {
2319
2319
let address_space = addr_space_of_ty ( ty) ;
2320
2320
let tcx = cx. tcx ( ) ;
2321
- let kind = match mt {
2322
- hir:: Mutability :: Not => {
2323
- if ty. is_freeze ( tcx. at ( DUMMY_SP ) , cx. param_env ( ) ) {
2324
- PointerKind :: Frozen
2325
- } else {
2326
- PointerKind :: Shared
2321
+ let kind = if tcx. sess . opts . optimize == OptLevel :: No {
2322
+ // Use conservative pointer kind if not optimizing. This saves us the
2323
+ // Freeze/Unpin queries, and can save time in the codegen backend (noalias
2324
+ // attributes in LLVM have compile-time cost even in unoptimized builds).
2325
+ PointerKind :: Shared
2326
+ } else {
2327
+ match mt {
2328
+ hir:: Mutability :: Not => {
2329
+ if ty. is_freeze ( tcx. at ( DUMMY_SP ) , cx. param_env ( ) ) {
2330
+ PointerKind :: Frozen
2331
+ } else {
2332
+ PointerKind :: Shared
2333
+ }
2327
2334
}
2328
- }
2329
- hir :: Mutability :: Mut => {
2330
- // References to self-referential structures should not be considered
2331
- // noalias, as another pointer to the structure can be obtained, that
2332
- // is not based-on the original reference. We consider all !Unpin
2333
- // types to be potentially self-referential here.
2334
- if ty . is_unpin ( tcx . at ( DUMMY_SP ) , cx . param_env ( ) ) {
2335
- PointerKind :: UniqueBorrowed
2336
- } else {
2337
- PointerKind :: Shared
2335
+ hir :: Mutability :: Mut => {
2336
+ // References to self-referential structures should not be considered
2337
+ // noalias, as another pointer to the structure can be obtained, that
2338
+ // is not based-on the original reference. We consider all !Unpin
2339
+ // types to be potentially self-referential here.
2340
+ if ty . is_unpin ( tcx . at ( DUMMY_SP ) , cx . param_env ( ) ) {
2341
+ PointerKind :: UniqueBorrowed
2342
+ } else {
2343
+ PointerKind :: Shared
2344
+ }
2338
2345
}
2339
2346
}
2340
2347
} ;
0 commit comments