[llvm] r341820 - [GVN] Invalidate cached info for values replaced by equality propagation
John Brawn via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 10 05:23:05 PDT 2018
Author: john.brawn
Date: Mon Sep 10 05:23:05 2018
New Revision: 341820
URL: http://llvm.org/viewvc/llvm-project?rev=341820&view=rev
Log:
[GVN] Invalidate cached info for values replaced by equality propagation
When GVN propagates an equality by replacing one value with another it also
needs to invalidate the cached information for the value being replaced.
Differential Revision: https://reviews.llvm.org/D51218
Modified:
llvm/trunk/lib/Transforms/Scalar/GVN.cpp
llvm/trunk/test/Transforms/GVN/condprop.ll
Modified: llvm/trunk/lib/Transforms/Scalar/GVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/GVN.cpp?rev=341820&r1=341819&r2=341820&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/GVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/GVN.cpp Mon Sep 10 05:23:05 2018
@@ -1736,6 +1736,9 @@ bool GVN::propagateEquality(Value *LHS,
Changed |= NumReplacements > 0;
NumGVNEqProp += NumReplacements;
+ // Cached information for anything that uses LHS will be invalid.
+ if (MD)
+ MD->invalidateCachedPointerInfo(LHS);
}
// Now try to deduce additional equalities from this one. For example, if
@@ -1811,6 +1814,9 @@ bool GVN::propagateEquality(Value *LHS,
Root.getStart());
Changed |= NumReplacements > 0;
NumGVNEqProp += NumReplacements;
+ // Cached information for anything that uses NotCmp will be invalid.
+ if (MD)
+ MD->invalidateCachedPointerInfo(NotCmp);
}
}
// Ensure that any instruction in scope that gets the "A < B" value number
Modified: llvm/trunk/test/Transforms/GVN/condprop.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GVN/condprop.ll?rev=341820&r1=341819&r2=341820&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GVN/condprop.ll (original)
+++ llvm/trunk/test/Transforms/GVN/condprop.ll Mon Sep 10 05:23:05 2018
@@ -297,3 +297,75 @@ ret:
; CHECK: %res = phi i32 [ 0, %cond_true ], [ %x, %cond_false ]
ret i32 %res
}
+
+; On the path from entry->if->end we know that ptr1==ptr2, so we can determine
+; that gep2 does not alias ptr1 on that path (as it would require that
+; ptr2==ptr2+2), so we can perform PRE of the load.
+; CHECK-LABEL: @test13
+define i32 @test13(i32* %ptr1, i32* %ptr2) {
+; CHECK-LABEL: entry:
+entry:
+ %gep1 = getelementptr i32, i32* %ptr2, i32 1
+ %gep2 = getelementptr i32, i32* %ptr2, i32 2
+ %cmp = icmp eq i32* %ptr1, %ptr2
+ br i1 %cmp, label %if, label %end
+
+; CHECK: [[CRIT_EDGE:.*]]:
+; CHECK: %[[PRE:.*]] = load i32, i32* %gep2, align 4
+
+; CHECK-LABEL: if:
+if:
+ %val1 = load i32, i32* %gep2, align 4
+ br label %end
+
+; CHECK-LABEL: end:
+; CHECK: %val2 = phi i32 [ %val1, %if ], [ %[[PRE]], %[[CRIT_EDGE]] ]
+; CHECK-NOT: load
+end:
+ %phi1 = phi i32* [ %ptr1, %if ], [ %gep1, %entry ]
+ %phi2 = phi i32 [ %val1, %if ], [ 0, %entry ]
+ store i32 0, i32* %phi1, align 4
+ %val2 = load i32, i32* %gep2, align 4
+ %ret = add i32 %phi2, %val2
+ ret i32 %ret
+}
+
+; CHECK-LABEL: @test14
+define void @test14(i32* %ptr1, i32* noalias %ptr2) {
+entry:
+ %gep1 = getelementptr inbounds i32, i32* %ptr1, i32 1
+ %gep2 = getelementptr inbounds i32, i32* %ptr1, i32 2
+ br label %loop
+
+; CHECK-LABEL: loop:
+loop:
+ %phi1 = phi i32* [ %gep3, %loop.end ], [ %gep1, %entry ]
+ br i1 undef, label %if1, label %then
+
+; CHECK: [[CRIT_EDGE:.*]]:
+; CHECK: %[[PRE:.*]] = load i32, i32* %gep2, align 4
+
+; CHECK-LABEL: if1:
+; CHECK: %val2 = phi i32 [ %[[PRE]], %[[CRIT_EDGE]] ], [ %val3, %loop.end ]
+; CHECK-NOT: load
+if1:
+ %val2 = load i32, i32* %gep2, align 4
+ store i32 %val2, i32* %gep2, align 4
+ store i32 0, i32* %phi1, align 4
+ br label %then
+
+; CHECK-LABEL: then:
+then:
+ %cmp = icmp eq i32* %gep2, %ptr2
+ br i1 %cmp, label %loop.end, label %if2
+
+if2:
+ br label %loop.end
+
+loop.end:
+ %phi3 = phi i32* [ %gep2, %then ], [ %ptr1, %if2 ]
+ %val3 = load i32, i32* %gep2, align 4
+ store i32 %val3, i32* %phi3, align 4
+ %gep3 = getelementptr inbounds i32, i32* %ptr1, i32 1
+ br i1 undef, label %loop, label %if1
+}
More information about the llvm-commits
mailing list