Cranelift: GVN all idempotently trapping but otherwise pure instructions (#5534)
This commit is contained in:
@@ -1686,7 +1686,8 @@ pub(crate) fn define(
|
||||
)
|
||||
.operands_in(vec![x, y])
|
||||
.operands_out(vec![a])
|
||||
.can_trap(true),
|
||||
.can_trap(true)
|
||||
.side_effects_idempotent(true),
|
||||
);
|
||||
|
||||
ig.push(
|
||||
@@ -1704,7 +1705,8 @@ pub(crate) fn define(
|
||||
)
|
||||
.operands_in(vec![x, y])
|
||||
.operands_out(vec![a])
|
||||
.can_trap(true),
|
||||
.can_trap(true)
|
||||
.side_effects_idempotent(true),
|
||||
);
|
||||
|
||||
ig.push(
|
||||
@@ -1719,7 +1721,8 @@ pub(crate) fn define(
|
||||
)
|
||||
.operands_in(vec![x, y])
|
||||
.operands_out(vec![a])
|
||||
.can_trap(true),
|
||||
.can_trap(true)
|
||||
.side_effects_idempotent(true),
|
||||
);
|
||||
|
||||
ig.push(
|
||||
@@ -1734,7 +1737,8 @@ pub(crate) fn define(
|
||||
)
|
||||
.operands_in(vec![x, y])
|
||||
.operands_out(vec![a])
|
||||
.can_trap(true),
|
||||
.can_trap(true)
|
||||
.side_effects_idempotent(true),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3324,7 +3328,8 @@ pub(crate) fn define(
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![a])
|
||||
.can_trap(true),
|
||||
.can_trap(true)
|
||||
.side_effects_idempotent(true),
|
||||
);
|
||||
|
||||
ig.push(
|
||||
@@ -3342,7 +3347,8 @@ pub(crate) fn define(
|
||||
)
|
||||
.operands_in(vec![x])
|
||||
.operands_out(vec![a])
|
||||
.can_trap(true),
|
||||
.can_trap(true)
|
||||
.side_effects_idempotent(true),
|
||||
);
|
||||
|
||||
let x = &Operand::new("x", Float);
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
;; Test that we GVN instructions that can trap (which is idempotent as long as
|
||||
;; it isn't a resumable trap), but which are still otherwise pure functions of
|
||||
;; their inputs.
|
||||
|
||||
test simple-gvn
|
||||
|
||||
function %udiv(i32, i32) -> i32 {
|
||||
block0(v0: i32, v1: i32):
|
||||
v2 = udiv v0, v1
|
||||
v3 = udiv v0, v1
|
||||
v4 = iadd v2, v3
|
||||
; check: v4 = iadd v2, v2
|
||||
return v4
|
||||
}
|
||||
|
||||
function %sdiv(i32, i32) -> i32 {
|
||||
block0(v0: i32, v1: i32):
|
||||
v2 = sdiv v0, v1
|
||||
v3 = sdiv v0, v1
|
||||
v4 = iadd v2, v3
|
||||
; check: v4 = iadd v2, v2
|
||||
return v4
|
||||
}
|
||||
|
||||
function %urem(i32, i32) -> i32 {
|
||||
block0(v0: i32, v1: i32):
|
||||
v2 = urem v0, v1
|
||||
v3 = urem v0, v1
|
||||
v4 = iadd v2, v3
|
||||
; check: v4 = iadd v2, v2
|
||||
return v4
|
||||
}
|
||||
|
||||
function %srem(i32, i32) -> i32 {
|
||||
block0(v0: i32, v1: i32):
|
||||
v2 = srem v0, v1
|
||||
v3 = srem v0, v1
|
||||
v4 = iadd v2, v3
|
||||
; check: v4 = iadd v2, v2
|
||||
return v4
|
||||
}
|
||||
|
||||
function %uadd_overflow_trap(i32, i32) -> i32 {
|
||||
block0(v0: i32, v1: i32):
|
||||
v2 = uadd_overflow_trap v0, v1, heap_oob
|
||||
v3 = uadd_overflow_trap v0, v1, heap_oob
|
||||
v4 = iadd v2, v3
|
||||
; check: v4 = iadd v2, v2
|
||||
return v4
|
||||
}
|
||||
|
||||
function %fcvt_to_uint(f32) -> i32 {
|
||||
block0(v0: f32):
|
||||
v1 = fcvt_to_uint.i32 v0
|
||||
v2 = fcvt_to_uint.i32 v0
|
||||
v3 = iadd v1, v2
|
||||
; check: v3 = iadd v1, v1
|
||||
return v3
|
||||
}
|
||||
|
||||
function %fcvt_to_sint(f32) -> i32 {
|
||||
block0(v0: f32):
|
||||
v1 = fcvt_to_sint.i32 v0
|
||||
v2 = fcvt_to_sint.i32 v0
|
||||
v3 = iadd v1, v2
|
||||
; check: v3 = iadd v1, v1
|
||||
return v3
|
||||
}
|
||||
Reference in New Issue
Block a user