Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 831e291

Browse files
committed
Auto merge of #145358 - Kobzol:symbol-name-sort, r=nnethercote
Sort mono items by symbol name Trying to claw back cycles/branch/cache miss losses from #144722.
2 parents d127901 + 6f1c998 commit 831e291

File tree

2 files changed

+60
-43
lines changed

2 files changed

+60
-43
lines changed

‎compiler/rustc_middle/src/mir/mono.rs‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,27 @@ impl<'tcx> CodegenUnit<'tcx> {
548548

549549
let mut items: Vec<_> = self.items().iter().map(|(&i, &data)| (i, data)).collect();
550550
if !tcx.sess.opts.unstable_opts.codegen_source_order {
551-
// It's already deterministic, so we can just use it.
552-
return items;
551+
// In this case, we do not need to keep the items in any specific order, as the input
552+
// is already deterministic.
553+
//
554+
// However, it seems that moving related things (such as different
555+
// monomorphizations of the same function) close to one another is actually beneficial
556+
// for LLVM performance.
557+
// LLVM will codegen the items in the order we pass them to it, and when it handles
558+
// similar things in succession, it seems that it leads to better cache utilization,
559+
// less branch mispredictions and in general to better performance.
560+
// For example, if we have functions `a`, `c::<u32>`, `b`, `c::<i16>`, `d` and
561+
// `c::<bool>`, it seems that it helps LLVM's performance to codegen the three `c`
562+
// instantiations right after one another, as they will likely reference similar types,
563+
// call similar functions, etc.
564+
//
565+
// See https://github.com/rust-lang/rust/pull/145358 for more details.
566+
//
567+
// Sorting by symbol name should not incur any new non-determinism.
568+
items.sort_by_cached_key(|&(i, _)| i.symbol_name(tcx));
569+
} else {
570+
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
553571
}
554-
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
555572
items
556573
}
557574

‎tests/ui/intrinsics/non-integer-atomic.stderr‎

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basi
44
LL | intrinsics::atomic_load::<_, { SeqCst }>(p);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7+
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer or pointer type, found `&dyn Fn()`
8+
--> $DIR/non-integer-atomic.rs:65:5
9+
|
10+
LL | intrinsics::atomic_xchg::<_, { SeqCst }>(p, v);
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
713
error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer or pointer type, found `Foo`
814
--> $DIR/non-integer-atomic.rs:35:5
915
|
1016
LL | intrinsics::atomic_load::<_, { SeqCst }>(p);
1117
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1218

13-
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer or pointer type, found `&dyn Fn()`
14-
--> $DIR/non-integer-atomic.rs:60:5
15-
|
16-
LL | intrinsics::atomic_store::<_, { SeqCst }>(p, v);
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18-
19-
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer or pointer type, found `[u8; 100]`
20-
--> $DIR/non-integer-atomic.rs:85:5
19+
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer or pointer type, found `Foo`
20+
--> $DIR/non-integer-atomic.rs:45:5
2121
|
2222
LL | intrinsics::atomic_xchg::<_, { SeqCst }>(p, v);
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -28,71 +28,71 @@ error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected bas
2828
LL | intrinsics::atomic_cxchg::<_, { SeqCst }, { SeqCst }>(p, v, v);
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030

31-
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer or pointer type, found `Foo`
32-
--> $DIR/non-integer-atomic.rs:40:5
31+
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer or pointer type, found `&dyn Fn()`
32+
--> $DIR/non-integer-atomic.rs:60:5
3333
|
3434
LL | intrinsics::atomic_store::<_, { SeqCst }>(p, v);
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3636

37-
error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer or pointer type, found `[u8; 100]`
38-
--> $DIR/non-integer-atomic.rs:90:5
37+
error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer or pointer type, found `Foo`
38+
--> $DIR/non-integer-atomic.rs:50:5
3939
|
4040
LL | intrinsics::atomic_cxchg::<_, { SeqCst }, { SeqCst }>(p, v, v);
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4242

43-
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer or pointer type, found `[u8; 100]`
44-
--> $DIR/non-integer-atomic.rs:80:5
45-
|
46-
LL | intrinsics::atomic_store::<_, { SeqCst }>(p, v);
47-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48-
49-
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer or pointer type, found `bool`
50-
--> $DIR/non-integer-atomic.rs:20:5
43+
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer or pointer type, found `Foo`
44+
--> $DIR/non-integer-atomic.rs:40:5
5145
|
5246
LL | intrinsics::atomic_store::<_, { SeqCst }>(p, v);
5347
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5448

55-
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer or pointer type, found `&dyn Fn()`
56-
--> $DIR/non-integer-atomic.rs:65:5
57-
|
58-
LL | intrinsics::atomic_xchg::<_, { SeqCst }>(p, v);
59-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60-
6149
error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer or pointer type, found `[u8; 100]`
6250
--> $DIR/non-integer-atomic.rs:75:5
6351
|
6452
LL | intrinsics::atomic_load::<_, { SeqCst }>(p);
6553
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6654

55+
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer or pointer type, found `[u8; 100]`
56+
--> $DIR/non-integer-atomic.rs:85:5
57+
|
58+
LL | intrinsics::atomic_xchg::<_, { SeqCst }>(p, v);
59+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
6761
error[E0511]: invalid monomorphization of `atomic_load` intrinsic: expected basic integer or pointer type, found `bool`
6862
--> $DIR/non-integer-atomic.rs:15:5
6963
|
7064
LL | intrinsics::atomic_load::<_, { SeqCst }>(p);
7165
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7266

73-
error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer or pointer type, found `bool`
74-
--> $DIR/non-integer-atomic.rs:30:5
67+
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer or pointer type, found `bool`
68+
--> $DIR/non-integer-atomic.rs:25:5
7569
|
76-
LL | intrinsics::atomic_cxchg::<_, { SeqCst }, { SeqCst }>(p, v, v);
77-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
70+
LL | intrinsics::atomic_xchg::<_, { SeqCst }>(p, v);
71+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7872

79-
error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer or pointer type, found `Foo`
80-
--> $DIR/non-integer-atomic.rs:50:5
73+
error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer or pointer type, found `[u8; 100]`
74+
--> $DIR/non-integer-atomic.rs:90:5
8175
|
8276
LL | intrinsics::atomic_cxchg::<_, { SeqCst }, { SeqCst }>(p, v, v);
8377
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8478

85-
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer or pointer type, found `Foo`
86-
--> $DIR/non-integer-atomic.rs:45:5
79+
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer or pointer type, found `[u8; 100]`
80+
--> $DIR/non-integer-atomic.rs:80:5
8781
|
88-
LL | intrinsics::atomic_xchg::<_, { SeqCst }>(p, v);
89-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82+
LL | intrinsics::atomic_store::<_, { SeqCst }>(p, v);
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9084

91-
error[E0511]: invalid monomorphization of `atomic_xchg` intrinsic: expected basic integer or pointer type, found `bool`
92-
--> $DIR/non-integer-atomic.rs:25:5
85+
error[E0511]: invalid monomorphization of `atomic_cxchg` intrinsic: expected basic integer or pointer type, found `bool`
86+
--> $DIR/non-integer-atomic.rs:30:5
9387
|
94-
LL | intrinsics::atomic_xchg::<_, { SeqCst }>(p, v);
95-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
88+
LL | intrinsics::atomic_cxchg::<_, { SeqCst }, { SeqCst }>(p, v, v);
89+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
90+
91+
error[E0511]: invalid monomorphization of `atomic_store` intrinsic: expected basic integer or pointer type, found `bool`
92+
--> $DIR/non-integer-atomic.rs:20:5
93+
|
94+
LL | intrinsics::atomic_store::<_, { SeqCst }>(p, v);
95+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9696

9797
error: aborting due to 16 previous errors
9898

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /