summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/GVN.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-21 04:11:19 +0000
committerChris Lattner <sabre@nondot.org>2009-10-21 04:11:19 +0000
commita52fce49eb3ee08a4829faf68e32476ff717893b (patch)
tree6480fd58f075fa8c7d4789ca9d6670a984359b0b /lib/Transforms/Scalar/GVN.cpp
parent1ce75ef5efd6e12ddf62d6f428bf9da960ff7880 (diff)
downloadllvm-a52fce49eb3ee08a4829faf68e32476ff717893b.tar.gz
llvm-a52fce49eb3ee08a4829faf68e32476ff717893b.tar.bz2
llvm-a52fce49eb3ee08a4829faf68e32476ff717893b.tar.xz
make GVN work better when TD is not around:
"In the existing code, if the load and the value to replace it with are of different types *and* target data is available, it tries to use the target data to coerce the replacement value to the type of the load. Otherwise, it skips all effort to handle the type mismatch and just feeds the wrongly-typed replacement value to replaceAllUsesWith, which triggers an assertion. The patch replaces it with an outer if checking for type mismatch, and an inner if-else that checks whether target data is available and, if not, returns false rather than trying to replace the load." Patch by Kenneth Uildriks! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84739 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/GVN.cpp')
-rw-r--r--lib/Transforms/Scalar/GVN.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index ef6c3389c9..8859324914 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/lib/Transforms/Scalar/GVN.cpp
@@ -1530,15 +1530,18 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl<Instruction*> &toErase) {
// actually have the same type. See if we know how to reuse the stored
// value (depending on its type).
const TargetData *TD = 0;
- if (StoredVal->getType() != L->getType() &&
- (TD = getAnalysisIfAvailable<TargetData>())) {
- StoredVal = CoerceAvailableValueToLoadType(StoredVal, L->getType(),
- L, *TD);
- if (StoredVal == 0)
+ if (StoredVal->getType() != L->getType()) {
+ if ((TD = getAnalysisIfAvailable<TargetData>())) {
+ StoredVal = CoerceAvailableValueToLoadType(StoredVal, L->getType(),
+ L, *TD);
+ if (StoredVal == 0)
+ return false;
+
+ DEBUG(errs() << "GVN COERCED STORE:\n" << *DepSI << '\n' << *StoredVal
+ << '\n' << *L << "\n\n\n");
+ }
+ else
return false;
-
- DEBUG(errs() << "GVN COERCED STORE:\n" << *DepSI << '\n' << *StoredVal
- << '\n' << *L << "\n\n\n");
}
// Remove it!
@@ -1557,14 +1560,17 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl<Instruction*> &toErase) {
// the same type. See if we know how to reuse the previously loaded value
// (depending on its type).
const TargetData *TD = 0;
- if (DepLI->getType() != L->getType() &&
- (TD = getAnalysisIfAvailable<TargetData>())) {
- AvailableVal = CoerceAvailableValueToLoadType(DepLI, L->getType(), L,*TD);
- if (AvailableVal == 0)
- return false;
+ if (DepLI->getType() != L->getType()) {
+ if ((TD = getAnalysisIfAvailable<TargetData>())) {
+ AvailableVal = CoerceAvailableValueToLoadType(DepLI, L->getType(), L,*TD);
+ if (AvailableVal == 0)
+ return false;
- DEBUG(errs() << "GVN COERCED LOAD:\n" << *DepLI << "\n" << *AvailableVal
- << "\n" << *L << "\n\n\n");
+ DEBUG(errs() << "GVN COERCED LOAD:\n" << *DepLI << "\n" << *AvailableVal
+ << "\n" << *L << "\n\n\n");
+ }
+ else
+ return false;
}
// Remove it!