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!

llvm-svn: 84739
This commit is contained in:
Chris Lattner 2009-10-21 04:11:19 +00:00
parent 175d04c90f
commit 8ed7bef409
1 changed files with 21 additions and 15 deletions

View File

@ -1530,8 +1530,8 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl<Instruction*> &toErase) {
// actually have the same type. See if we know how to reuse the stored // actually have the same type. See if we know how to reuse the stored
// value (depending on its type). // value (depending on its type).
const TargetData *TD = 0; const TargetData *TD = 0;
if (StoredVal->getType() != L->getType() && if (StoredVal->getType() != L->getType()) {
(TD = getAnalysisIfAvailable<TargetData>())) { if ((TD = getAnalysisIfAvailable<TargetData>())) {
StoredVal = CoerceAvailableValueToLoadType(StoredVal, L->getType(), StoredVal = CoerceAvailableValueToLoadType(StoredVal, L->getType(),
L, *TD); L, *TD);
if (StoredVal == 0) if (StoredVal == 0)
@ -1540,6 +1540,9 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl<Instruction*> &toErase) {
DEBUG(errs() << "GVN COERCED STORE:\n" << *DepSI << '\n' << *StoredVal DEBUG(errs() << "GVN COERCED STORE:\n" << *DepSI << '\n' << *StoredVal
<< '\n' << *L << "\n\n\n"); << '\n' << *L << "\n\n\n");
} }
else
return false;
}
// Remove it! // Remove it!
L->replaceAllUsesWith(StoredVal); L->replaceAllUsesWith(StoredVal);
@ -1557,8 +1560,8 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl<Instruction*> &toErase) {
// the same type. See if we know how to reuse the previously loaded value // the same type. See if we know how to reuse the previously loaded value
// (depending on its type). // (depending on its type).
const TargetData *TD = 0; const TargetData *TD = 0;
if (DepLI->getType() != L->getType() && if (DepLI->getType() != L->getType()) {
(TD = getAnalysisIfAvailable<TargetData>())) { if ((TD = getAnalysisIfAvailable<TargetData>())) {
AvailableVal = CoerceAvailableValueToLoadType(DepLI, L->getType(), L,*TD); AvailableVal = CoerceAvailableValueToLoadType(DepLI, L->getType(), L,*TD);
if (AvailableVal == 0) if (AvailableVal == 0)
return false; return false;
@ -1566,6 +1569,9 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl<Instruction*> &toErase) {
DEBUG(errs() << "GVN COERCED LOAD:\n" << *DepLI << "\n" << *AvailableVal DEBUG(errs() << "GVN COERCED LOAD:\n" << *DepLI << "\n" << *AvailableVal
<< "\n" << *L << "\n\n\n"); << "\n" << *L << "\n\n\n");
} }
else
return false;
}
// Remove it! // Remove it!
L->replaceAllUsesWith(AvailableVal); L->replaceAllUsesWith(AvailableVal);