rust/compiler
Nicholas Nethercote 003a3f8cd3 Use br instead of switch in more cases.
`codegen_switchint_terminator` already uses `br` instead of `switch`
when there is one normal target plus the `otherwise` target. But there's
another common case with two normal targets and an `otherwise` target
that points to an empty unreachable BB. This comes up a lot when
switching on the tags of enums that use niches.

The pattern looks like this:
```
bb1:                                              ; preds = %bb6
  %3 = load i8, ptr %_2, align 1, !range !9, !noundef !4
  %4 = sub i8 %3, 2
  %5 = icmp eq i8 %4, 0
  %_6 = select i1 %5, i64 0, i64 1
  switch i64 %_6, label %bb3 [
    i64 0, label %bb4
    i64 1, label %bb2
  ]

bb3:                                              ; preds = %bb1
  unreachable
```
This commit adds code to convert the `switch` to a `br`:
```
bb1:                                              ; preds = %bb6
  %3 = load i8, ptr %_2, align 1, !range !9, !noundef !4
  %4 = sub i8 %3, 2
  %5 = icmp eq i8 %4, 0
  %_6 = select i1 %5, i64 0, i64 1
  %6 = icmp eq i64 %_6, 0
  br i1 %6, label %bb4, label %bb2

bb3:                                              ; No predecessors!
  unreachable
```
This has a surprisingly large effect on compile times, with reductions
of 5% on debug builds of some crates. The reduction is all due to LLVM
taking less time. Maybe LLVM is just much better at handling `br` than
`switch`.

The resulting code is still suboptimal.
- The `icmp`, `select`, `icmp` sequence is silly, converting an `i1` to an `i64`
  and back to an `i1`. But with the current code structure it's hard to avoid,
  and LLVM will easily clean it up, in opt builds at least.
- `bb3` is usually now truly dead code (though not always, so it can't
  be removed universally).
2022-10-31 10:16:39 +11:00
..
rustc
rustc_apfloat
rustc_arena
rustc_ast remove unused parser fn 2022-10-26 19:19:44 +00:00
rustc_ast_lowering Rollup merge of #93582 - WaffleLapkin:rpitirpit, r=compiler-errors 2022-10-30 11:50:26 +05:30
rustc_ast_passes Rollup merge of #95710 - fee1-dead-contrib:stabilize_arbitrary_enum_discriminant, r=joshtriplett 2022-10-26 17:32:53 +05:30
rustc_ast_pretty Rename AssocItemKind::TyAlias to AssocItemKind::Type 2022-10-10 02:31:37 +00:00
rustc_attr Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_borrowck Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors 2022-10-29 14:18:03 +02:00
rustc_builtin_macros Rollup merge of #103430 - cjgillot:receiver-attrs, r=petrochenkov 2022-10-26 11:29:55 +05:30
rustc_codegen_cranelift Update tooling 2022-10-27 18:41:26 +04:00
rustc_codegen_gcc Support raw-dylib functions being used inside inlined functions 2022-10-24 16:17:38 -07:00
rustc_codegen_llvm Auto merge of #103299 - nikic:usub-overflow, r=wesleywiser 2022-10-30 17:45:04 +00:00
rustc_codegen_ssa Use br instead of switch in more cases. 2022-10-31 10:16:39 +11:00
rustc_const_eval Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors 2022-10-29 14:18:03 +02:00
rustc_data_structures Introduce UnordMap, UnordSet, and UnordBag (see MCP 533) 2022-10-27 13:23:26 +00:00
rustc_driver Remove rustc_driver::set_sigpipe_handler() 2022-10-25 19:13:23 +02:00
rustc_error_codes Rollup merge of #95710 - fee1-dead-contrib:stabilize_arbitrary_enum_discriminant, r=joshtriplett 2022-10-26 17:32:53 +05:30
rustc_error_messages Rollup merge of #103383 - compiler-errors:tait-scope, r=oli-obk 2022-10-29 08:57:35 +02:00
rustc_errors Allow specifying multiple alternative suggestions 2022-10-23 18:59:13 +02:00
rustc_expand Rollup merge of #103544 - Nilstrieb:no-recovery-pls, r=compiler-errors 2022-10-27 15:03:58 +02:00
rustc_feature Rollup merge of #93582 - WaffleLapkin:rpitirpit, r=compiler-errors 2022-10-30 11:50:26 +05:30
rustc_fs_util
rustc_graphviz
rustc_hir Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_hir_analysis Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors 2022-10-29 14:18:03 +02:00
rustc_hir_pretty pretty: fix to print some lifetimes on HIR pretty-print 2022-10-15 23:34:21 +09:00
rustc_hir_typeck Rollup merge of #103699 - compiler-errors:dyn-star-cast-bad, r=TaKO8Ki 2022-10-29 14:18:05 +02:00
rustc_incremental Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_index
rustc_infer Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_interface Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_lexer rustc_lexer::TokenKind improve docs 2022-10-26 23:32:14 +02:00
rustc_lint Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors 2022-10-29 14:18:03 +02:00
rustc_lint_defs Rollup merge of #102635 - lcnr:incoherent_auto_trait_objects, r=jackh726 2022-10-22 00:13:59 +02:00
rustc_llvm llvm-16: Don't initialize removed legacy passes 2022-10-25 15:03:21 -07:00
rustc_log
rustc_macros Allow specifying multiple alternative suggestions 2022-10-23 18:59:13 +02:00
rustc_metadata Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_middle Use br instead of switch in more cases. 2022-10-31 10:16:39 +11:00
rustc_mir_build Rollup merge of #103726 - TaKO8Ki:avoid-&str-to-string-conversions, r=compiler-errors 2022-10-30 00:09:26 +02:00
rustc_mir_dataflow Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_mir_transform Accept TyCtxt instead of TyCtxtAt in Ty::is_* functions 2022-10-27 15:06:08 +04:00
rustc_monomorphize Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors 2022-10-29 14:18:03 +02:00
rustc_parse Rollup merge of #103544 - Nilstrieb:no-recovery-pls, r=compiler-errors 2022-10-27 15:03:58 +02:00
rustc_parse_format
rustc_passes Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_plugin_impl Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_privacy Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_query_impl Introduce UnordMap, UnordSet, and UnordBag (see MCP 533) 2022-10-27 13:23:26 +00:00
rustc_query_system Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_resolve Rollup merge of #103560 - zbyrn:issue-103358-fix, r=cjgillot 2022-10-30 11:50:26 +05:30
rustc_save_analysis Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_serialize
rustc_session Introduce dedicated -Zdylib-lto flag for enabling LTO on dylibs 2022-10-23 13:48:03 +02:00
rustc_smir
rustc_span Rollup merge of #93582 - WaffleLapkin:rpitirpit, r=compiler-errors 2022-10-30 11:50:26 +05:30
rustc_symbol_mangling Rename some OwnerId fields. 2022-10-29 20:28:38 +11:00
rustc_target Split is_stable from rustc_target::spec::abi::is_enabled. 2022-10-19 12:41:11 +02:00
rustc_trait_selection Rollup merge of #103726 - TaKO8Ki:avoid-&str-to-string-conversions, r=compiler-errors 2022-10-30 00:09:26 +02:00
rustc_traits rm try_normalize_mir_const_after_erasing_regions 2022-10-17 10:54:03 +02:00
rustc_transmute
rustc_ty_utils Rollup merge of #103625 - WaffleLapkin:no_tyctxt_dogs_allowed, r=compiler-errors 2022-10-29 14:18:03 +02:00
rustc_type_ir Deny const variables as well 2022-10-19 17:11:40 +00:00