Skip to content

Commit

Permalink
cranelift: Translate stack_* accesses as unaligned (#6016)
Browse files Browse the repository at this point in the history
We can't currently ensure that these will be aligned, so we shouldn't mark them as such.
  • Loading branch information
afonso360 authored Mar 15, 2023
1 parent 6ed90f8 commit a10c50a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 6 additions & 4 deletions cranelift/codegen/src/legalizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa:

let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);

// Stack slots are required to be accessible and aligned.
let mflags = MemFlags::trusted();
// Stack slots are required to be accessible.
// We can't currently ensure that they are aligned.
let mut mflags = MemFlags::new();
mflags.set_notrap();
pos.func.dfg.replace(inst).load(ty, mflags, addr, 0);
}
InstructionData::StackStore {
Expand All @@ -99,10 +101,10 @@ pub fn simple_legalize(func: &mut ir::Function, cfg: &mut ControlFlowGraph, isa:

let addr = pos.ins().stack_addr(addr_ty, stack_slot, offset);

// Stack slots are required to be accessible.
// We can't currently ensure that they are aligned.
let mut mflags = MemFlags::new();
// Stack slots are required to be accessible and aligned.
mflags.set_notrap();
mflags.set_aligned();
pos.func.dfg.replace(inst).store(mflags, arg, addr, 0);
}
InstructionData::DynamicStackLoad {
Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/egraph/misc.clif
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ block0(v0: i64):
; nextln: ss0 = explicit_slot 8
; check: block0(v0: i64):
; nextln: v2 = stack_addr.i64 ss0
; nextln: store notrap aligned v0, v2
; nextln: store notrap v0, v2
; nextln: return v0
; nextln: }
16 changes: 16 additions & 0 deletions cranelift/filetests/filetests/runtests/simd-extractlane.clif
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,19 @@ block0(v0: f64x2):
return v4
}
; run: %extractlane_f64x2_through_stack([0x1.0 0x2.0]) == 0x1.0


function %unaligned_extractlane() -> f64 {
ss0 = explicit_slot 24

block0:
v0 = iconst.i64 0
stack_store.i64 v0, ss0+0
stack_store.i64 v0, ss0+8
stack_store.i64 v0, ss0+16

v1 = stack_load.f64x2 ss0+1
v2 = extractlane v1, 1
return v2
}
; run: %unaligned_extractlane() == 0.0

0 comments on commit a10c50a

Please sign in to comment.