Add a readonly flag for loads (#562)
* Add readonly MemFlag * Add readonly flag verifier check * Make global loads readonly * Fix gvn to consider readonly loads
This commit is contained in:
committed by
Dan Gohman
parent
3ec21459c5
commit
586a8835e9
@@ -502,12 +502,13 @@ Memory operation flags
|
||||
Loads and stores can have flags that loosen their semantics in order to enable
|
||||
optimizations.
|
||||
|
||||
======= ===========================================
|
||||
Flag Description
|
||||
======= ===========================================
|
||||
notrap Memory is assumed to be :term:`accessible`.
|
||||
aligned Trapping allowed for misaligned accesses.
|
||||
======= ===========================================
|
||||
======= ===========================================
|
||||
Flag Description
|
||||
======= ===========================================
|
||||
notrap Memory is assumed to be :term:`accessible`.
|
||||
aligned Trapping allowed for misaligned accesses.
|
||||
readonly The data at the specified address will not modified between when this function is called and exited.
|
||||
======= ===========================================
|
||||
|
||||
When the ``accessible`` flag is set, the behavior is undefined if the memory
|
||||
is not :term:`accessible`.
|
||||
|
||||
25
cranelift/filetests/simple_gvn/readonly.clif
Normal file
25
cranelift/filetests/simple_gvn/readonly.clif
Normal file
@@ -0,0 +1,25 @@
|
||||
test simple-gvn
|
||||
|
||||
target x86_64
|
||||
|
||||
function %eliminate_redundant_global_loads(i32, i64 vmctx) {
|
||||
gv0 = vmctx
|
||||
gv1 = load.i64 notrap aligned readonly gv0
|
||||
heap0 = static gv1, min 0x1_0000, bound 0x1_0000_0000, guard 0x8000_0000, index_type i32
|
||||
|
||||
ebb0(v0: i32, v1: i64):
|
||||
v2 = heap_addr.i64 heap0, v0, 1
|
||||
v3 = heap_addr.i64 heap0, v0, 1
|
||||
|
||||
v4 = iconst.i32 0
|
||||
store.i32 notrap aligned v4, v2
|
||||
store.i32 notrap aligned v4, v3
|
||||
|
||||
return
|
||||
}
|
||||
; check: v2 = heap_addr.i64 heap0, v0, 1
|
||||
; check: v3 -> v2
|
||||
; check: v4 = iconst.i32 0
|
||||
; check: store notrap aligned v4, v2
|
||||
; check: store notrap aligned v4, v2
|
||||
; check: return
|
||||
Reference in New Issue
Block a user