1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

[WebAssembly] Don't stackify stores across instructions with side effects.

llvm-svn: 258285
This commit is contained in:
Dan Gohman 2016-01-20 04:21:16 +00:00
parent e690f5b8b2
commit e0f4353910
3 changed files with 37 additions and 13 deletions

View File

@ -128,7 +128,7 @@ static bool IsSafeToMove(const MachineInstr *Def, const MachineInstr *Insert,
// Check for memory dependencies and side effects. // Check for memory dependencies and side effects.
for (--I; I != D; --I) for (--I; I != D; --I)
SawSideEffects |= I->isSafeToMove(&AA, SawStore); SawSideEffects |= !I->isSafeToMove(&AA, SawStore);
return !(SawStore && Def->mayLoad() && !Def->isInvariantLoad(&AA)) && return !(SawStore && Def->mayLoad() && !Def->isInvariantLoad(&AA)) &&
!(SawSideEffects && !Def->isSafeToMove(&AA, SawStore)); !(SawSideEffects && !Def->isSafeToMove(&AA, SawStore));
} }

View File

@ -128,4 +128,21 @@ return:
ret void ret void
} }
; Don't stackify stores effects across other instructions with side effects.
; CHECK: side_effects:
; CHECK: store
; CHECK-NEXT: call
; CHECK-NEXT: store
; CHECK-NEXT: call
declare void @evoke_side_effects()
define hidden void @stackify_store_across_side_effects(double* nocapture %d) {
entry:
store double 2.0, double* %d
call void @evoke_side_effects()
store double 2.0, double* %d
call void @evoke_side_effects()
ret void
}
!0 = !{} !0 = !{}

View File

@ -47,31 +47,37 @@ define void @alloca3264() {
} }
; CHECK-LABEL: allocarray: ; CHECK-LABEL: allocarray:
; CHECK: .local i32, i32, i32, i32, i32, i32{{$}} ; CHECK: .local i32, i32, i32, i32, i32{{$}}
define void @allocarray() { define void @allocarray() {
; CHECK: i32.const [[L1:.+]]=, __stack_pointer ; CHECK-NEXT: i32.const [[L1:.+]]=, __stack_pointer
; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]]) ; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]])
; CHECK-NEXT: i32.const [[L2:.+]]=, 32 ; CHECK-NEXT: i32.const [[L2:.+]]=, 32{{$}}
; CHECK-NEXT: i32.sub [[SP:.+]]=, [[L1]], [[L2]] ; CHECK-NEXT: i32.sub [[SP:.+]]=, [[L1]], [[L2]]
; CHECK-NEXT: i32.const [[L2]]=, __stack_pointer{{$}}
; CHECK-NEXT: i32.store [[SP]]=, 0([[L2]]), [[SP]]
%r = alloca [5 x i32] %r = alloca [5 x i32]
; CHECK: i32.const $push[[L3:.+]]=, 1
; CHECK: i32.store {{.*}}=, 12([[SP]]), $pop[[L3]] ; CHECK-NEXT: i32.const $push[[L4:.+]]=, 4
; CHECK-NEXT: i32.const [[L5:.+]]=, 12
; CHECK-NEXT: i32.add [[L5]]=, [[SP]], [[L5]]
; CHECK-NEXT: i32.add $push[[L6:.+]]=, [[L5]], $pop[[L4]]
; CHECK-NEXT: i32.const $push[[L9:.+]]=, 1{{$}}
; CHECK-NEXT: i32.store $push[[L10:.+]]=, 12([[SP]]), $pop[[L9]]{{$}}
; CHECK-NEXT: i32.store $discard=, 0($pop3), $pop[[L10]]{{$}}
%p = getelementptr [5 x i32], [5 x i32]* %r, i32 0, i32 0 %p = getelementptr [5 x i32], [5 x i32]* %r, i32 0, i32 0
store i32 1, i32* %p store i32 1, i32* %p
; CHECK: i32.const $push[[L4:.+]]=, 4
; CHECK: i32.const [[L5:.+]]=, 12
; CHECK: i32.add [[L5]]=, [[SP]], [[L5]]
; CHECK: i32.add $push[[L6:.+]]=, [[L5]], $pop[[L4]]
; CHECK: i32.store {{.*}}=, 0($pop[[L6]]), ${{.+}}
%p2 = getelementptr [5 x i32], [5 x i32]* %r, i32 0, i32 1 %p2 = getelementptr [5 x i32], [5 x i32]* %r, i32 0, i32 1
store i32 1, i32* %p2 store i32 1, i32* %p2
; CHECK: i32.const [[L7:.+]]=, 32
; CHECK-NEXT: i32.const [[L7:.+]]=, 32
; CHECK-NEXT: i32.add [[SP]]=, [[SP]], [[L7]] ; CHECK-NEXT: i32.add [[SP]]=, [[SP]], [[L7]]
; CHECK-NEXT: i32.const [[L8:.+]]=, __stack_pointer ; CHECK-NEXT: i32.const [[L8:.+]]=, __stack_pointer
; CHECK-NEXT: i32.store [[SP]]=, 0([[L7]]), [[SP]] ; CHECK-NEXT: i32.store [[SP]]=, 0([[L8]]), [[SP]]
ret void ret void
} }
; CHECK-LABEL: allocarray_inbounds:
; CHECK: .local i32, i32, i32, i32{{$}}
define void @allocarray_inbounds() { define void @allocarray_inbounds() {
; CHECK: i32.const [[L1:.+]]=, __stack_pointer ; CHECK: i32.const [[L1:.+]]=, __stack_pointer
; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]]) ; CHECK-NEXT: i32.load [[L1]]=, 0([[L1]])
@ -93,6 +99,7 @@ define void @allocarray_inbounds() {
ret void ret void
} }
; CHECK-LABEL: dynamic_alloca:
define void @dynamic_alloca(i32 %alloc) { define void @dynamic_alloca(i32 %alloc) {
; TODO: Support frame pointers ; TODO: Support frame pointers
;%r = alloca i32, i32 %alloc ;%r = alloca i32, i32 %alloc