[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LowerPacked.cpp SCCP.cpp
Robert L. Bocchino Jr.
bocchino at persephone.cs.uiuc.edu
Tue Jan 17 12:08:01 PST 2006
Changes in directory llvm/lib/Transforms/Scalar:
LowerPacked.cpp updated: 1.7 -> 1.8
SCCP.cpp updated: 1.126 -> 1.127
---
Log message:
Lowerpacked and SCCP support for the insertelement operation.
---
Diffs of the changes: (+66 -8)
LowerPacked.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++--------
SCCP.cpp | 21 +++++++++++++++++++++
2 files changed, 66 insertions(+), 8 deletions(-)
Index: llvm/lib/Transforms/Scalar/LowerPacked.cpp
diff -u llvm/lib/Transforms/Scalar/LowerPacked.cpp:1.7 llvm/lib/Transforms/Scalar/LowerPacked.cpp:1.8
--- llvm/lib/Transforms/Scalar/LowerPacked.cpp:1.7 Tue Jan 10 13:05:05 2006
+++ llvm/lib/Transforms/Scalar/LowerPacked.cpp Tue Jan 17 14:06:55 2006
@@ -61,8 +61,12 @@
/// @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,22 +349,55 @@
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);
}
Changed = true;
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)
Index: llvm/lib/Transforms/Scalar/SCCP.cpp
diff -u llvm/lib/Transforms/Scalar/SCCP.cpp:1.126 llvm/lib/Transforms/Scalar/SCCP.cpp:1.127
--- llvm/lib/Transforms/Scalar/SCCP.cpp:1.126 Tue Jan 10 13:05:05 2006
+++ llvm/lib/Transforms/Scalar/SCCP.cpp Tue Jan 17 14:06:55 2006
@@ -323,6 +323,7 @@
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);
@@ -738,6 +739,26 @@
else if(ValState.isConstant() && IdxState.isConstant())
markConstant(&I, ConstantExpr::getExtractElement(ValState.getConstant(),
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
More information about the llvm-commits
mailing list