mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
enhance logic to support ConstantDataArray.
llvm-svn: 149340
This commit is contained in:
parent
7761976036
commit
054e412291
@ -203,8 +203,12 @@ FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, GlobalVariable *GV,
|
|||||||
// We need TD information to know the pointer size unless this is inbounds.
|
// We need TD information to know the pointer size unless this is inbounds.
|
||||||
if (!GEP->isInBounds() && TD == 0) return 0;
|
if (!GEP->isInBounds() && TD == 0) return 0;
|
||||||
|
|
||||||
ConstantArray *Init = dyn_cast<ConstantArray>(GV->getInitializer());
|
Constant *Init = GV->getInitializer();
|
||||||
if (Init == 0 || Init->getNumOperands() > 1024) return 0;
|
if (!isa<ConstantArray>(Init) && !isa<ConstantDataArray>(Init))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
uint64_t ArrayElementCount = Init->getType()->getArrayNumElements();
|
||||||
|
if (ArrayElementCount > 1024) return 0; // Don't blow up on huge arrays.
|
||||||
|
|
||||||
// There are many forms of this optimization we can handle, for now, just do
|
// There are many forms of this optimization we can handle, for now, just do
|
||||||
// the simple index into a single-dimensional array.
|
// the simple index into a single-dimensional array.
|
||||||
@ -221,7 +225,7 @@ FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, GlobalVariable *GV,
|
|||||||
// structs.
|
// structs.
|
||||||
SmallVector<unsigned, 4> LaterIndices;
|
SmallVector<unsigned, 4> LaterIndices;
|
||||||
|
|
||||||
Type *EltTy = cast<ArrayType>(Init->getType())->getElementType();
|
Type *EltTy = Init->getType()->getArrayElementType();
|
||||||
for (unsigned i = 3, e = GEP->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 3, e = GEP->getNumOperands(); i != e; ++i) {
|
||||||
ConstantInt *Idx = dyn_cast<ConstantInt>(GEP->getOperand(i));
|
ConstantInt *Idx = dyn_cast<ConstantInt>(GEP->getOperand(i));
|
||||||
if (Idx == 0) return 0; // Variable index.
|
if (Idx == 0) return 0; // Variable index.
|
||||||
@ -272,8 +276,9 @@ FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, GlobalVariable *GV,
|
|||||||
|
|
||||||
// Scan the array and see if one of our patterns matches.
|
// Scan the array and see if one of our patterns matches.
|
||||||
Constant *CompareRHS = cast<Constant>(ICI.getOperand(1));
|
Constant *CompareRHS = cast<Constant>(ICI.getOperand(1));
|
||||||
for (unsigned i = 0, e = Init->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = ArrayElementCount; i != e; ++i) {
|
||||||
Constant *Elt = Init->getOperand(i);
|
Constant *Elt = Init->getAggregateElement(i);
|
||||||
|
if (Elt == 0) return 0;
|
||||||
|
|
||||||
// If this is indexing an array of structures, get the structure element.
|
// If this is indexing an array of structures, get the structure element.
|
||||||
if (!LaterIndices.empty())
|
if (!LaterIndices.empty())
|
||||||
@ -440,10 +445,10 @@ FoldCmpLoadFromIndexedGlobal(GetElementPtrInst *GEP, GlobalVariable *GV,
|
|||||||
// If a 32-bit or 64-bit magic bitvector captures the entire comparison state
|
// If a 32-bit or 64-bit magic bitvector captures the entire comparison state
|
||||||
// of this load, replace it with computation that does:
|
// of this load, replace it with computation that does:
|
||||||
// ((magic_cst >> i) & 1) != 0
|
// ((magic_cst >> i) & 1) != 0
|
||||||
if (Init->getNumOperands() <= 32 ||
|
if (ArrayElementCount <= 32 ||
|
||||||
(TD && Init->getNumOperands() <= 64 && TD->isLegalInteger(64))) {
|
(TD && ArrayElementCount <= 64 && TD->isLegalInteger(64))) {
|
||||||
Type *Ty;
|
Type *Ty;
|
||||||
if (Init->getNumOperands() <= 32)
|
if (ArrayElementCount <= 32)
|
||||||
Ty = Type::getInt32Ty(Init->getContext());
|
Ty = Type::getInt32Ty(Init->getContext());
|
||||||
else
|
else
|
||||||
Ty = Type::getInt64Ty(Init->getContext());
|
Ty = Type::getInt64Ty(Init->getContext());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user