Cranelift: mark post-legalization trapping blocks as cold (#5367)
Trapping is a rare event.
This commit is contained in:
@@ -304,6 +304,9 @@ fn expand_cond_trap(
|
||||
let new_block_trap = 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.
|
||||
if trapz {
|
||||
func.dfg.replace(inst).brnz(arg, new_block_resume, &[]);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user