@@ -106,12 +106,6 @@ use std::borrow::Cow;
106
106
use crate :: ssa:: { AssignedValue , SsaLocals } ;
107
107
use either:: Either ;
108
108
109
- // LLVM optimizes the load of 16 byte as a single `mov`.
110
- // Bigger values make more `mov` instructions generated.
111
- // While changing code as this lint suggests, it becomes
112
- // a single load (`lea`) of an address in `.rodata`.
113
- const STACK_THRESHOLD : u64 = 16 ;
114
-
115
109
pub struct GVN ;
116
110
117
111
impl < ' tcx > MirPass < ' tcx > for GVN {
@@ -373,6 +367,11 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
373
367
#[ instrument( level = "trace" , skip( self ) , ret) ]
374
368
fn eval_to_const ( & mut self , value : VnIndex ) -> Option < OpTy < ' tcx > > {
375
369
use Value :: * ;
370
+ use abi:: HasDataLayout ;
371
+ // LLVM optimizes the load of `sizeof(size_t) * 2` as a single `mov`,
372
+ // which is cheap. Bigger values make more `mov` instructions generated.
373
+ // After GVN, it becomes a single load (`lea`) of an address in `.rodata`.
374
+ let stack_threshold = self . tcx . data_layout ( ) . pointer_size * 2 ;
376
375
let vvalue = self . get ( value) ;
377
376
debug ! ( ?vvalue) ;
378
377
let op = match * vvalue {
@@ -417,7 +416,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
417
416
let ptr_imm = Immediate :: new_pointer_with_meta ( data, meta, & self . ecx ) ;
418
417
ImmTy :: from_immediate ( ptr_imm, ty) . into ( )
419
418
} else if matches ! ( kind, AggregateTy :: Array ) {
420
- if ty. layout . size ( ) . bytes ( ) <= STACK_THRESHOLD {
419
+ if ty. layout . size ( ) <= stack_threshold {
421
420
return None ;
422
421
}
423
422
let mut mplace = None ;
0 commit comments