mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[EarlyCSE] Don't hide earler invariant.scopes
If we've already established an invariant scope with an earlier generation, we don't want to hide it in the scoped hash table with one with a later generation. I noticed this when working on the invariant-load handling, but it also applies to the invariant.start case as well. Without this change, my previous patch for invariant-load regresses some cases, so I'm pushing this without waiting for review. This is why you don't make last minute tweaks to patches to catch "obvious cases" after it's already been reviewed. Bad Philip! llvm-svn: 327655
This commit is contained in:
parent
e83983d4d1
commit
ec5a97390b
@ -799,7 +799,9 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
|
|||||||
continue;
|
continue;
|
||||||
auto *CI = cast<CallInst>(Inst);
|
auto *CI = cast<CallInst>(Inst);
|
||||||
MemoryLocation MemLoc = MemoryLocation::getForArgument(CI, 1, TLI);
|
MemoryLocation MemLoc = MemoryLocation::getForArgument(CI, 1, TLI);
|
||||||
AvailableInvariants.insert(MemLoc, CurrentGeneration);
|
// Don't start a scope if we already have a better one pushed
|
||||||
|
if (!AvailableInvariants.count(MemLoc))
|
||||||
|
AvailableInvariants.insert(MemLoc, CurrentGeneration);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -888,9 +890,12 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
|
|||||||
if (MemInst.isInvariantLoad()) {
|
if (MemInst.isInvariantLoad()) {
|
||||||
// If we pass an invariant load, we know that memory location is
|
// If we pass an invariant load, we know that memory location is
|
||||||
// indefinitely constant from the moment of first dereferenceability.
|
// indefinitely constant from the moment of first dereferenceability.
|
||||||
// We conservatively treat the invariant_load as that moment.
|
// We conservatively treat the invariant_load as that moment. If we
|
||||||
|
// pass a invariant load after already establishing a scope, don't
|
||||||
|
// restart it since we want to preserve the earliest point seen.
|
||||||
auto MemLoc = MemoryLocation::get(Inst);
|
auto MemLoc = MemoryLocation::get(Inst);
|
||||||
AvailableInvariants.insert(MemLoc, CurrentGeneration);
|
if (!AvailableInvariants.count(MemLoc))
|
||||||
|
AvailableInvariants.insert(MemLoc, CurrentGeneration);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have an available version of this load, and if it is the right
|
// If we have an available version of this load, and if it is the right
|
||||||
|
@ -135,3 +135,24 @@ define void @test_scope_start_without_load(i32* %p) {
|
|||||||
call void @clobber_and_use(i32 %v3)
|
call void @clobber_and_use(i32 %v3)
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; If we already have an invariant scope, don't want to start a new one
|
||||||
|
; with a potentially greater generation. This hides the earlier invariant
|
||||||
|
; load
|
||||||
|
define void @test_scope_restart(i32* %p) {
|
||||||
|
; CHECK-LABEL: @test_scope_restart
|
||||||
|
; CHECK: %v1 = load i32, i32* %p
|
||||||
|
; CHECK: call void @clobber_and_use(i32 %v1)
|
||||||
|
; CHECK: %add = add i32 %v1, %v1
|
||||||
|
; CHECK: call void @clobber_and_use(i32 %add)
|
||||||
|
; CHECK: call void @clobber_and_use(i32 %v1)
|
||||||
|
; CHECK: ret void
|
||||||
|
%v1 = load i32, i32* %p, !invariant.load !{}
|
||||||
|
call void @clobber_and_use(i32 %v1)
|
||||||
|
%v2 = load i32, i32* %p, !invariant.load !{}
|
||||||
|
%add = add i32 %v1, %v2
|
||||||
|
call void @clobber_and_use(i32 %add)
|
||||||
|
%v3 = load i32, i32* %p
|
||||||
|
call void @clobber_and_use(i32 %v3)
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
@ -93,6 +93,18 @@ define i32 @test_before_clobber(i32* %p) {
|
|||||||
ret i32 %sub
|
ret i32 %sub
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i32 @test_duplicate_scope(i32* %p) {
|
||||||
|
; CHECK-LABEL: @test_duplicate_scope
|
||||||
|
; CHECK: ret i32 0
|
||||||
|
%v1 = load i32, i32* %p
|
||||||
|
call {}* @llvm.invariant.start.p0i32(i64 4, i32* %p)
|
||||||
|
call void @clobber()
|
||||||
|
call {}* @llvm.invariant.start.p0i32(i64 4, i32* %p)
|
||||||
|
%v2 = load i32, i32* %p
|
||||||
|
%sub = sub i32 %v1, %v2
|
||||||
|
ret i32 %sub
|
||||||
|
}
|
||||||
|
|
||||||
define i32 @test_unanalzyable_load(i32* %p) {
|
define i32 @test_unanalzyable_load(i32* %p) {
|
||||||
; CHECK-LABEL: @test_unanalzyable_load
|
; CHECK-LABEL: @test_unanalzyable_load
|
||||||
; CHECK: ret i32 0
|
; CHECK: ret i32 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user