[llvm] r280265 - [EarlyCSE] Allow forwarding a non-invariant load into an invariant load.
Geoff Berry via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 10:45:32 PDT 2016
Author: gberry
Date: Wed Aug 31 12:45:31 2016
New Revision: 280265
URL: http://llvm.org/viewvc/llvm-project?rev=280265&view=rev
Log:
[EarlyCSE] Allow forwarding a non-invariant load into an invariant load.
Reviewers: sanjoy
Subscribers: mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D23935
Modified:
llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
llvm/trunk/test/Transforms/EarlyCSE/invariant-loads.ll
Modified: llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp?rev=280265&r1=280264&r2=280265&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp Wed Aug 31 12:45:31 2016
@@ -644,13 +644,13 @@ bool EarlyCSE::processNode(DomTreeNode *
// generation or the load is known to be from an invariant location,
// replace this instruction.
//
- // A dominating invariant load implies that the location loaded from is
- // unchanging beginning at the point of the invariant load, so the load
- // we're CSE'ing _away_ does not need to be invariant, only the available
- // load we're CSE'ing _to_ does.
+ // If either the dominating load or the current load are invariant, then
+ // we can assume the current load loads the same value as the dominating
+ // load.
LoadValue InVal = AvailableLoads.lookup(MemInst.getPointerOperand());
if (InVal.DefInst != nullptr &&
- (InVal.Generation == CurrentGeneration || InVal.IsInvariant) &&
+ (InVal.Generation == CurrentGeneration ||
+ InVal.IsInvariant || MemInst.isInvariantLoad()) &&
InVal.MatchingId == MemInst.getMatchingId() &&
// We don't yet handle removing loads with ordering of any kind.
!MemInst.isVolatile() && MemInst.isUnordered() &&
Modified: llvm/trunk/test/Transforms/EarlyCSE/invariant-loads.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/EarlyCSE/invariant-loads.ll?rev=280265&r1=280264&r2=280265&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/EarlyCSE/invariant-loads.ll (original)
+++ llvm/trunk/test/Transforms/EarlyCSE/invariant-loads.ll Wed Aug 31 12:45:31 2016
@@ -20,9 +20,7 @@ define void @f_0(i32* %ptr) {
}
define void @f_1(i32* %ptr) {
-; We can forward invariant loads to non-invariant loads, since once an
-; invariant load has executed, the location loaded from is known to be
-; unchanging.
+; We can forward invariant loads to non-invariant loads.
; CHECK-LABEL: @f_1(
; CHECK: %val0 = load i32, i32* %ptr, !invariant.load !0
@@ -37,14 +35,12 @@ define void @f_1(i32* %ptr) {
}
define void @f_2(i32* %ptr) {
-; Negative test -- we can't forward a non-invariant load into an
-; invariant load.
+; We can forward a non-invariant load into an invariant load.
; CHECK-LABEL: @f_2(
; CHECK: %val0 = load i32, i32* %ptr
; CHECK: call void @clobber_and_use(i32 %val0)
-; CHECK: %val1 = load i32, i32* %ptr, !invariant.load !0
-; CHECK: call void @clobber_and_use(i32 %val1)
+; CHECK: call void @clobber_and_use(i32 %val0)
%val0 = load i32, i32* %ptr
call void @clobber_and_use(i32 %val0)
More information about the llvm-commits
mailing list