summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2016-08-19 20:09:03 +0000
committerTim Northover <tnorthover@apple.com>2016-08-19 20:09:03 +0000
commitb604622bbaa7dae77e60db7afe75a6cef55ea5c4 (patch)
tree27bd7234f4f74151f3aa4a9857d204f47ed81695 /llvm/lib/CodeGen
parent96f981268fe68389c32037c28a4377668c5afe78 (diff)
downloadbcm5719-llvm-b604622bbaa7dae77e60db7afe75a6cef55ea5c4.tar.gz
bcm5719-llvm-b604622bbaa7dae77e60db7afe75a6cef55ea5c4.zip
GlobalISel: fix insert/extract to work on ConstantExprs too.
No tests yet unfortunately (ConstantFolding reduces all supported constants to ConstantInts before we get to translation). Soon. llvm-svn: 279308
Diffstat (limited to 'llvm/lib/CodeGen')
-rw-r--r--llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp45
1 files changed, 27 insertions, 18 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index fb348e9a6c7..3c1807fbd2e 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -183,50 +183,59 @@ bool IRTranslator::translateStore(const User &U) {
}
bool IRTranslator::translateExtractValue(const User &U) {
- const ExtractValueInst &EVI = cast<ExtractValueInst>(U);
- const Value *Src = EVI.getAggregateOperand();
- Type *Int32Ty = Type::getInt32Ty(EVI.getContext());
+ const Value *Src = U.getOperand(0);
+ Type *Int32Ty = Type::getInt32Ty(U.getContext());
SmallVector<Value *, 1> Indices;
// getIndexedOffsetInType is designed for GEPs, so the first index is the
// usual array element rather than looking into the actual aggregate.
Indices.push_back(ConstantInt::get(Int32Ty, 0));
- for (auto Idx : EVI.indices())
- Indices.push_back(ConstantInt::get(Int32Ty, Idx));
+
+ if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(&U)) {
+ for (auto Idx : EVI->indices())
+ Indices.push_back(ConstantInt::get(Int32Ty, Idx));
+ } else {
+ for (unsigned i = 1; i < U.getNumOperands(); ++i)
+ Indices.push_back(U.getOperand(i));
+ }
uint64_t Offset = 8 * DL->getIndexedOffsetInType(Src->getType(), Indices);
- unsigned Res = getOrCreateVReg(EVI);
- MIRBuilder.buildExtract(LLT{*EVI.getType(), DL}, Res, Offset,
+ unsigned Res = getOrCreateVReg(U);
+ MIRBuilder.buildExtract(LLT{*U.getType(), DL}, Res, Offset,
LLT{*Src->getType(), DL}, getOrCreateVReg(*Src));
return true;
}
bool IRTranslator::translateInsertValue(const User &U) {
- const InsertValueInst &IVI = cast<InsertValueInst>(U);
- const Value *Src = IVI.getAggregateOperand();
- Type *Int32Ty = Type::getInt32Ty(IVI.getContext());
+ const Value *Src = U.getOperand(0);
+ Type *Int32Ty = Type::getInt32Ty(U.getContext());
SmallVector<Value *, 1> Indices;
// getIndexedOffsetInType is designed for GEPs, so the first index is the
// usual array element rather than looking into the actual aggregate.
Indices.push_back(ConstantInt::get(Int32Ty, 0));
- for (auto Idx : IVI.indices())
- Indices.push_back(ConstantInt::get(Int32Ty, Idx));
+
+ if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(&U)) {
+ for (auto Idx : IVI->indices())
+ Indices.push_back(ConstantInt::get(Int32Ty, Idx));
+ } else {
+ for (unsigned i = 2; i < U.getNumOperands(); ++i)
+ Indices.push_back(U.getOperand(i));
+ }
uint64_t Offset = 8 * DL->getIndexedOffsetInType(Src->getType(), Indices);
- unsigned Res = getOrCreateVReg(IVI);
- const Value &Inserted = *IVI.getInsertedValueOperand();
- MIRBuilder.buildInsert(
- LLT{*IVI.getType(), DL}, Res, getOrCreateVReg(*IVI.getAggregateOperand()),
- LLT{*Inserted.getType(), DL}, getOrCreateVReg(Inserted), Offset);
+ unsigned Res = getOrCreateVReg(U);
+ const Value &Inserted = *U.getOperand(1);
+ MIRBuilder.buildInsert(LLT{*U.getType(), DL}, Res, getOrCreateVReg(*Src),
+ LLT{*Inserted.getType(), DL},
+ getOrCreateVReg(Inserted), Offset);
return true;
}
-
bool IRTranslator::translateBitCast(const User &U) {
if (LLT{*U.getOperand(0)->getType()} == LLT{*U.getType()}) {
unsigned &Reg = ValToVReg[&U];
OpenPOWER on IntegriCloud