aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Bocchino <bocchino@illinois.edu>2006-01-17 20:06:55 +0000
committerRobert Bocchino <bocchino@illinois.edu>2006-01-17 20:06:55 +0000
commit8fcf01ead0ab0a43df2440fa93088ca746a37a47 (patch)
tree5c90c7f1e6a4f53d930ba0b318c1248d8dad2836
parent4eb2e3a6f45e6f0a4a8f0002918f8d14c34169c1 (diff)
downloadexternal_llvm-8fcf01ead0ab0a43df2440fa93088ca746a37a47.zip
external_llvm-8fcf01ead0ab0a43df2440fa93088ca746a37a47.tar.gz
external_llvm-8fcf01ead0ab0a43df2440fa93088ca746a37a47.tar.bz2
Lowerpacked and SCCP support for the insertelement operation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25406 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/LowerPacked.cpp53
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp21
2 files changed, 66 insertions, 8 deletions
diff --git a/lib/Transforms/Scalar/LowerPacked.cpp b/lib/Transforms/Scalar/LowerPacked.cpp
index e8338bb..b24460c 100644
--- a/lib/Transforms/Scalar/LowerPacked.cpp
+++ b/lib/Transforms/Scalar/LowerPacked.cpp
@@ -61,7 +61,11 @@ public:
/// @brief Lowers packed extractelement instructions.
/// @param EI the extractelement operator to convert
- void visitExtractElementInst(ExtractElementInst& EI);
+ void visitExtractElementInst(ExtractElementInst& EE);
+
+ /// @brief Lowers packed insertelement instructions.
+ /// @param EI the insertelement operator to convert
+ void visitInsertElementInst(InsertElementInst& IE);
/// This function asserts if the instruction is a PackedType but
/// is handled by another function.
@@ -345,16 +349,19 @@ void LowerPacked::visitExtractElementInst(ExtractElementInst& EI)
if (ConstantUInt *C = dyn_cast<ConstantUInt>(op1)) {
EI.replaceAllUsesWith(op0Vals[C->getValue()]);
} else {
- AllocaInst *alloca = new AllocaInst(PTy->getElementType(),
- ConstantUInt::get(Type::UIntTy, PTy->getNumElements()),
- EI.getName() + ".alloca", &(EI.getParent()->getParent()->getEntryBlock().front()));
+ AllocaInst *alloca =
+ new AllocaInst(PTy->getElementType(),
+ ConstantUInt::get(Type::UIntTy, PTy->getNumElements()),
+ EI.getName() + ".alloca",
+ EI.getParent()->getParent()->getEntryBlock().begin());
for (unsigned i = 0; i < PTy->getNumElements(); ++i) {
- GetElementPtrInst *GEP = new GetElementPtrInst(alloca, ConstantUInt::get(Type::UIntTy, i),
- "store.ge", &EI);
+ GetElementPtrInst *GEP =
+ new GetElementPtrInst(alloca, ConstantUInt::get(Type::UIntTy, i),
+ "store.ge", &EI);
new StoreInst(op0Vals[i], GEP, &EI);
}
- GetElementPtrInst *GEP = new GetElementPtrInst(alloca, op1,
- EI.getName() + ".ge", &EI);
+ GetElementPtrInst *GEP =
+ new GetElementPtrInst(alloca, op1, EI.getName() + ".ge", &EI);
LoadInst *load = new LoadInst(GEP, EI.getName() + ".load", &EI);
EI.replaceAllUsesWith(load);
}
@@ -363,6 +370,36 @@ void LowerPacked::visitExtractElementInst(ExtractElementInst& EI)
instrsToRemove.push_back(&EI);
}
+void LowerPacked::visitInsertElementInst(InsertElementInst& IE)
+{
+ std::vector<Value*>& Vals = getValues(IE.getOperand(0));
+ Value *Elt = IE.getOperand(1);
+ Value *Idx = IE.getOperand(2);
+ std::vector<Value*> result;
+ result.reserve(Vals.size());
+
+ if (ConstantUInt *C = dyn_cast<ConstantUInt>(Idx)) {
+ unsigned idxVal = C->getValue();
+ for (unsigned i = 0; i != Vals.size(); ++i) {
+ result.push_back(i == idxVal ? Elt : Vals[i]);
+ }
+ } else {
+ for (unsigned i = 0; i != Vals.size(); ++i) {
+ SetCondInst *setcc =
+ new SetCondInst(Instruction::SetEQ, Idx,
+ ConstantUInt::get(Type::UIntTy, i),
+ "setcc", &IE);
+ SelectInst *select =
+ new SelectInst(setcc, Elt, Vals[i], "select", &IE);
+ result.push_back(select);
+ }
+ }
+
+ setValues(&IE, result);
+ Changed = true;
+ instrsToRemove.push_back(&IE);
+}
+
bool LowerPacked::runOnFunction(Function& F)
{
// initialize
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 1a76eb5..9e98248 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -323,6 +323,7 @@ private:
void visitBinaryOperator(Instruction &I);
void visitShiftInst(ShiftInst &I) { visitBinaryOperator(I); }
void visitExtractElementInst(ExtractElementInst &I);
+ void visitInsertElementInst(InsertElementInst &I);
// Instructions that cannot be folded away...
void visitStoreInst (Instruction &I);
@@ -740,6 +741,26 @@ void SCCPSolver::visitExtractElementInst(ExtractElementInst &I) {
IdxState.getConstant()));
}
+void SCCPSolver::visitInsertElementInst(InsertElementInst &I) {
+ LatticeVal &ValState = getValueState(I.getOperand(0));
+ LatticeVal &EltState = getValueState(I.getOperand(1));
+ LatticeVal &IdxState = getValueState(I.getOperand(2));
+
+ if (ValState.isOverdefined() || EltState.isOverdefined() ||
+ IdxState.isOverdefined())
+ markOverdefined(&I);
+ else if(ValState.isConstant() && EltState.isConstant() &&
+ IdxState.isConstant())
+ markConstant(&I, ConstantExpr::getInsertElement(ValState.getConstant(),
+ EltState.getConstant(),
+ IdxState.getConstant()));
+ else if (ValState.isUndefined() && EltState.isConstant() &&
+ IdxState.isConstant())
+ markConstant(&I, ConstantExpr::getInsertElement(UndefValue::get(I.getType()),
+ EltState.getConstant(),
+ IdxState.getConstant()));
+}
+
// Handle getelementptr instructions... if all operands are constants then we
// can turn this into a getelementptr ConstantExpr.
//