[llvm] r373807 - Invalidate assumption cache before outlining.
Aditya Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 15:46:42 PDT 2019
Author: hiraditya
Date: Fri Oct 4 15:46:42 2019
New Revision: 373807
URL: http://llvm.org/viewvc/llvm-project?rev=373807&view=rev
Log:
Invalidate assumption cache before outlining.
Subscribers: llvm-commits
Tags: #llvm
Reviewers: compnerd, vsk, sebpop, fhahn, tejohnson
Reviewed by: vsk
Differential Revision: https://reviews.llvm.org/D68478
Modified:
llvm/trunk/include/llvm/Transforms/Utils/CodeExtractor.h
llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp
llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp
llvm/trunk/test/Transforms/HotColdSplit/assumption-cache-invalidation.ll
Modified: llvm/trunk/include/llvm/Transforms/Utils/CodeExtractor.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/CodeExtractor.h?rev=373807&r1=373806&r2=373807&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/CodeExtractor.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/CodeExtractor.h Fri Oct 4 15:46:42 2019
@@ -106,6 +106,11 @@ class Value;
/// returns false.
Function *extractCodeRegion();
+ /// Verify that assumption cache isn't stale after a region is extracted.
+ /// Returns false when verifier finds errors. AssumptionCache is passed as
+ /// parameter to make this function stateless.
+ static bool verifyAssumptionCache(const Function& F, AssumptionCache *AC);
+
/// Test whether this code extractor is eligible.
///
/// Based on the blocks used when constructing the code extractor,
Modified: llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp?rev=373807&r1=373806&r2=373807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp Fri Oct 4 15:46:42 2019
@@ -628,11 +628,6 @@ bool HotColdSplitting::outlineColdRegion
} while (!Region.empty());
}
- // We need to explicitly clear the assumption cache since the value tracking
- // may now be invalid as part of the function has changed.
- if (Changed)
- if (AssumptionCache *AC = LookupAC(F))
- AC->clear();
return Changed;
}
Modified: llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp?rev=373807&r1=373806&r2=373807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp Fri Oct 4 15:46:42 2019
@@ -1301,13 +1301,6 @@ void CodeExtractor::moveCodeToFunction(F
// Insert this basic block into the new function
newBlocks.push_back(Block);
-
- // Remove @llvm.assume calls that were moved to the new function from the
- // old function's assumption cache.
- if (AC)
- for (auto &I : *Block)
- if (match(&I, m_Intrinsic<Intrinsic::assume>()))
- AC->unregisterAssumption(cast<CallInst>(&I));
}
}
@@ -1378,6 +1371,15 @@ Function *CodeExtractor::extractCodeRegi
}
}
+ if (AC) {
+ // Remove @llvm.assume calls that were moved to the new function from the
+ // old function's assumption cache.
+ for (BasicBlock *Block : Blocks)
+ for (auto &I : *Block)
+ if (match(&I, m_Intrinsic<Intrinsic::assume>()))
+ AC->unregisterAssumption(cast<CallInst>(&I));
+ }
+
// If we have any return instructions in the region, split those blocks so
// that the return is not in the region.
splitReturnBlocks();
@@ -1568,5 +1570,17 @@ Function *CodeExtractor::extractCodeRegi
});
LLVM_DEBUG(if (verifyFunction(*oldFunction))
report_fatal_error("verification of oldFunction failed!"));
+ LLVM_DEBUG(if (AC && verifyAssumptionCache(*oldFunction, AC))
+ report_fatal_error("Stale Asumption cache for old Function!"));
return newFunction;
}
+
+bool CodeExtractor::verifyAssumptionCache(const Function& F,
+ AssumptionCache *AC) {
+ for (auto AssumeVH : AC->assumptions()) {
+ CallInst *I = cast<CallInst>(AssumeVH);
+ if (I->getFunction() != &F)
+ return true;
+ }
+ return false;
+}
Modified: llvm/trunk/test/Transforms/HotColdSplit/assumption-cache-invalidation.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/HotColdSplit/assumption-cache-invalidation.ll?rev=373807&r1=373806&r2=373807&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/HotColdSplit/assumption-cache-invalidation.ll (original)
+++ llvm/trunk/test/Transforms/HotColdSplit/assumption-cache-invalidation.ll Fri Oct 4 15:46:42 2019
@@ -1,3 +1,5 @@
+; REQUIRES: asserts
+; RUN: opt -S -instsimplify -hotcoldsplit -debug < %s 2>&1 | FileCheck %s
; RUN: opt -instcombine -hotcoldsplit -instsimplify %s -o /dev/null
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
@@ -6,6 +8,16 @@ target triple = "aarch64"
%a = type { i64, i64 }
%b = type { i64 }
+; CHECK: @f
+; CHECK-LABEL: codeRepl:
+; CHECK-NOT: @llvm.assume
+; CHECK: }
+; CHECK: declare {{.*}}@llvm.assume
+; CHECK: define {{.*}}@f.cold.1(i64 %0)
+; CHECK-LABEL: newFuncRoot:
+; CHECK: %1 = icmp eq i64 %0, 0
+; CHECK: call void @llvm.assume(i1 %1)
+
define void @f() {
entry:
%0 = getelementptr inbounds %a, %a* null, i64 0, i32 1
More information about the llvm-commits
mailing list