llvm.org GIT mirror llvm / 74711af
[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! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327655 91177308-0d34-0410-b5e6-96231b3b80d8 Philip Reames 1 year, 6 months ago
3 changed file(s) with 41 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
798798 continue;
799799 auto *CI = cast(Inst);
800800 MemoryLocation MemLoc = MemoryLocation::getForArgument(CI, 1, TLI);
801 AvailableInvariants.insert(MemLoc, CurrentGeneration);
801 // Don't start a scope if we already have a better one pushed
802 if (!AvailableInvariants.count(MemLoc))
803 AvailableInvariants.insert(MemLoc, CurrentGeneration);
802804 continue;
803805 }
804806
887889 if (MemInst.isInvariantLoad()) {
888890 // If we pass an invariant load, we know that memory location is
889891 // indefinitely constant from the moment of first dereferenceability.
890 // We conservatively treat the invariant_load as that moment.
892 // We conservatively treat the invariant_load as that moment. If we
893 // pass a invariant load after already establishing a scope, don't
894 // restart it since we want to preserve the earliest point seen.
891895 auto MemLoc = MemoryLocation::get(Inst);
892 AvailableInvariants.insert(MemLoc, CurrentGeneration);
896 if (!AvailableInvariants.count(MemLoc))
897 AvailableInvariants.insert(MemLoc, CurrentGeneration);
893898 }
894899
895900 // If we have an available version of this load, and if it is the right
134134 call void @clobber_and_use(i32 %v3)
135135 ret void
136136 }
137
138 ; If we already have an invariant scope, don't want to start a new one
139 ; with a potentially greater generation. This hides the earlier invariant
140 ; load
141 define void @test_scope_restart(i32* %p) {
142 ; CHECK-LABEL: @test_scope_restart
143 ; CHECK: %v1 = load i32, i32* %p
144 ; CHECK: call void @clobber_and_use(i32 %v1)
145 ; CHECK: %add = add i32 %v1, %v1
146 ; CHECK: call void @clobber_and_use(i32 %add)
147 ; CHECK: call void @clobber_and_use(i32 %v1)
148 ; CHECK: ret void
149 %v1 = load i32, i32* %p, !invariant.load !{}
150 call void @clobber_and_use(i32 %v1)
151 %v2 = load i32, i32* %p, !invariant.load !{}
152 %add = add i32 %v1, %v2
153 call void @clobber_and_use(i32 %add)
154 %v3 = load i32, i32* %p
155 call void @clobber_and_use(i32 %v3)
156 ret void
157 }
9292 ret i32 %sub
9393 }
9494
95 define i32 @test_duplicate_scope(i32* %p) {
96 ; CHECK-LABEL: @test_duplicate_scope
97 ; CHECK: ret i32 0
98 %v1 = load i32, i32* %p
99 call {}* @llvm.invariant.start.p0i32(i64 4, i32* %p)
100 call void @clobber()
101 call {}* @llvm.invariant.start.p0i32(i64 4, i32* %p)
102 %v2 = load i32, i32* %p
103 %sub = sub i32 %v1, %v2
104 ret i32 %sub
105 }
106
95107 define i32 @test_unanalzyable_load(i32* %p) {
96108 ; CHECK-LABEL: @test_unanalzyable_load
97109 ; CHECK: ret i32 0