summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/GVN.cpp
diff options
context:
space:
mode:
authorEkaterina Romanova <katya_romanova@playstation.sony.com>2016-07-14 22:02:25 +0000
committerEkaterina Romanova <katya_romanova@playstation.sony.com>2016-07-14 22:02:25 +0000
commit7aea5906c0cd284098294d9c626e8f9aae86fdbe (patch)
tree01d204d17dd6070f0f96cf2b4e498facc99d0c5b /llvm/lib/Transforms/Scalar/GVN.cpp
parent240414dc954fa0adc501242bc7a276fa5edb76fa (diff)
downloadbcm5719-llvm-7aea5906c0cd284098294d9c626e8f9aae86fdbe.tar.gz
bcm5719-llvm-7aea5906c0cd284098294d9c626e8f9aae86fdbe.zip
[GVN] Fold constant expression in GVN.
Fix for PR 28418. opt never finishes compiling a test when -gvn option is passed. The problem is caused by the fact that GVN fails to fold a constant expression. Differential Revision: https://reviews.llvm.org/D22185 llvm-svn: 275483
Diffstat (limited to 'llvm/lib/Transforms/Scalar/GVN.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/GVN.cpp55
1 files changed, 33 insertions, 22 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp
index a963b2f50ed..a35a1062cbc 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -725,6 +725,9 @@ static Value *CoerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy,
assert(CanCoerceMustAliasedValueToLoad(StoredVal, LoadedTy, DL) &&
"precondition violation - materialization can't fail");
+ if (auto *CExpr = dyn_cast<ConstantExpr>(StoredVal))
+ StoredVal = ConstantFoldConstantExpression(CExpr, DL);
+
// If this is already the right type, just return it.
Type *StoredValTy = StoredVal->getType();
@@ -735,25 +738,29 @@ static Value *CoerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy,
if (StoredValSize == LoadedValSize) {
// Pointer to Pointer -> use bitcast.
if (StoredValTy->getScalarType()->isPointerTy() &&
- LoadedTy->getScalarType()->isPointerTy())
- return IRB.CreateBitCast(StoredVal, LoadedTy);
+ LoadedTy->getScalarType()->isPointerTy()) {
+ StoredVal = IRB.CreateBitCast(StoredVal, LoadedTy);
+ } else {
+ // Convert source pointers to integers, which can be bitcast.
+ if (StoredValTy->getScalarType()->isPointerTy()) {
+ StoredValTy = DL.getIntPtrType(StoredValTy);
+ StoredVal = IRB.CreatePtrToInt(StoredVal, StoredValTy);
+ }
- // Convert source pointers to integers, which can be bitcast.
- if (StoredValTy->getScalarType()->isPointerTy()) {
- StoredValTy = DL.getIntPtrType(StoredValTy);
- StoredVal = IRB.CreatePtrToInt(StoredVal, StoredValTy);
- }
+ Type *TypeToCastTo = LoadedTy;
+ if (TypeToCastTo->getScalarType()->isPointerTy())
+ TypeToCastTo = DL.getIntPtrType(TypeToCastTo);
- Type *TypeToCastTo = LoadedTy;
- if (TypeToCastTo->getScalarType()->isPointerTy())
- TypeToCastTo = DL.getIntPtrType(TypeToCastTo);
+ if (StoredValTy != TypeToCastTo)
+ StoredVal = IRB.CreateBitCast(StoredVal, TypeToCastTo);
- if (StoredValTy != TypeToCastTo)
- StoredVal = IRB.CreateBitCast(StoredVal, TypeToCastTo);
+ // Cast to pointer if the load needs a pointer type.
+ if (LoadedTy->getScalarType()->isPointerTy())
+ StoredVal = IRB.CreateIntToPtr(StoredVal, LoadedTy);
+ }
- // Cast to pointer if the load needs a pointer type.
- if (LoadedTy->getScalarType()->isPointerTy())
- StoredVal = IRB.CreateIntToPtr(StoredVal, LoadedTy);
+ if (auto *CExpr = dyn_cast<ConstantExpr>(StoredVal))
+ StoredVal = ConstantFoldConstantExpression(CExpr, DL);
return StoredVal;
}
@@ -788,15 +795,19 @@ static Value *CoerceAvailableValueToLoadType(Value *StoredVal, Type *LoadedTy,
Type *NewIntTy = IntegerType::get(StoredValTy->getContext(), LoadedValSize);
StoredVal = IRB.CreateTrunc(StoredVal, NewIntTy, "trunc");
- if (LoadedTy == NewIntTy)
- return StoredVal;
+ if (LoadedTy != NewIntTy) {
+ // If the result is a pointer, inttoptr.
+ if (LoadedTy->getScalarType()->isPointerTy())
+ StoredVal = IRB.CreateIntToPtr(StoredVal, LoadedTy, "inttoptr");
+ else
+ // Otherwise, bitcast.
+ StoredVal = IRB.CreateBitCast(StoredVal, LoadedTy, "bitcast");
+ }
- // If the result is a pointer, inttoptr.
- if (LoadedTy->getScalarType()->isPointerTy())
- return IRB.CreateIntToPtr(StoredVal, LoadedTy, "inttoptr");
+ if (auto *CExpr = dyn_cast<ConstantExpr>(StoredVal))
+ StoredVal = ConstantFoldConstantExpression(CExpr, DL);
- // Otherwise, bitcast.
- return IRB.CreateBitCast(StoredVal, LoadedTy, "bitcast");
+ return StoredVal;
}
/// This function is called when we have a
OpenPOWER on IntegriCloud