mirror of
				https://github.com/rust-lang/rust.git
				synced 2025-10-31 13:04:42 +00:00 
			
		
		
		
	 143f39362a
			
		
	
	
		143f39362a
		
	
	
	
	
		
			
			Today we're making LLVM do a bunch of extra work for every enum you match on, even trivial stuff like `Option<bool>`. Let's not.
		
			
				
	
	
		
			38 lines
		
	
	
		
			738 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			738 B
		
	
	
	
		
			Rust
		
	
	
	
	
	
| //@ compile-flags: -O
 | |
| #![crate_type = "lib"]
 | |
| #![feature(core_intrinsics)]
 | |
| 
 | |
| use std::intrinsics::cold_path;
 | |
| 
 | |
| #[inline(never)]
 | |
| #[no_mangle]
 | |
| pub fn path_a() {
 | |
|     println!("path a");
 | |
| }
 | |
| 
 | |
| #[inline(never)]
 | |
| #[no_mangle]
 | |
| pub fn path_b() {
 | |
|     println!("path b");
 | |
| }
 | |
| 
 | |
| #[no_mangle]
 | |
| pub fn test(x: Option<bool>) {
 | |
|     if let Some(_) = x {
 | |
|         path_a();
 | |
|     } else {
 | |
|         cold_path();
 | |
|         path_b();
 | |
|     }
 | |
| 
 | |
|     // CHECK-LABEL: void @test(i8{{.+}}%x)
 | |
|     // CHECK: %[[IS_NONE:.+]] = icmp eq i8 %x, 2
 | |
|     // CHECK: br i1 %[[IS_NONE]], label %bb2, label %bb1, !prof ![[NUM:[0-9]+]]
 | |
|     // CHECK: bb1:
 | |
|     // CHECK: path_a
 | |
|     // CHECK: bb2:
 | |
|     // CHECK: path_b
 | |
| }
 | |
| 
 | |
| // CHECK: ![[NUM]] = !{!"branch_weights", {{(!"expected", )?}}i32 1, i32 2000}
 |