Skip to content

Commit 6b8b875

Browse files
committed
Sort mono items by symbol name
1 parent 350d0ef commit 6b8b875

File tree

2 files changed

+54
-43
lines changed

2 files changed

+54
-43
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,21 @@ impl<'tcx> CodegenUnit<'tcx> {
566566

567567
let mut items: Vec<_> = self.items().iter().map(|(&i, &data)| (i, data)).collect();
568568
if !tcx.sess.opts.unstable_opts.codegen_source_order {
569-
// It's already deterministic, so we can just use it.
570-
return items;
569+
// In this case, we do not need to keep the items in any specific order, as the input
570+
// is already deterministic.
571+
// However, it seems that actually moving related things (such as different
572+
// monomorphizations of the same function) close to one another is actually beneficial
573+
// for LLVM performance.
574+
// LLVM will codegen the items in the order we pass them to it, and when it handles
575+
// similar things in succession, it seems that it leads to better cache utilization,
576+
// less branch mispredictions and in general to better performance.
577+
// See https://github.com/rust-lang/rust/pull/145358 for more details.
578+
//
579+
// Sorting by symbol name should not incur any new non-determinism.
580+
items.sort_by_cached_key(|&(i, _)| i.symbol_name(tcx));
581+
} else {
582+
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
571583
}
572-
items.sort_by_cached_key(|&(i, _)| item_sort_key(tcx, i));
573584
items
574585
}
575586

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)