Cranelift: mark post-legalization trapping blocks as cold (#5367)

Trapping is a rare event.
This commit is contained in:
Nick Fitzgerald
2022-12-01 12:46:26 -08:00
committed by GitHub
parent 1eeec7b698
commit 4510a4a805
2 changed files with 43 additions and 0 deletions

View File

@@ -304,6 +304,9 @@ fn expand_cond_trap(
let new_block_trap = func.dfg.make_block(); let new_block_trap = func.dfg.make_block();
let new_block_resume = func.dfg.make_block(); let new_block_resume = func.dfg.make_block();
// Trapping is a rare event, mark the trapping block as cold.
func.layout.set_cold(new_block_trap);
// Replace trap instruction by the inverted condition. // Replace trap instruction by the inverted condition.
if trapz { if trapz {
func.dfg.replace(inst).brnz(arg, new_block_resume, &[]); func.dfg.replace(inst).brnz(arg, new_block_resume, &[]);

View File

@@ -0,0 +1,40 @@
;; Test the legalizations of `trap[n]z`.
test legalizer
target aarch64
target x86_64
target riscv64
target s390x
function %trapnz(i32) -> i32 {
block0(v0: i32):
trapnz v0, heap_oob
return v0
}
; check: block0(v0: i32):
; nextln: brz v0, block2
; nextln: jump block1
; nextln:
; nextln: block1 cold:
; nextln: trap heap_oob
; nextln:
; nextln: block2:
; nextln: return v0
function %trapz(i32) -> i32 {
block0(v0: i32):
trapz v0, heap_oob
return v0
}
; check: block0(v0: i32):
; nextln: brnz v0, block2
; nextln: jump block1
; nextln:
; nextln: block1 cold:
; nextln: trap heap_oob
; nextln:
; nextln: block2:
; nextln: return v0