[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LowerPacked.cpp SCCP.cpp

Robert L. Bocchino Jr. bocchino at persephone.cs.uiuc.edu
Tue Jan 10 11:06:26 PST 2006



Changes in directory llvm/lib/Transforms/Scalar:

LowerPacked.cpp updated: 1.6 -> 1.7
SCCP.cpp updated: 1.125 -> 1.126
---
Log message:

Added lower packed support for the extractelement operation.



---
Diffs of the changes:  (+43 -0)

 LowerPacked.cpp |   31 +++++++++++++++++++++++++++++++
 SCCP.cpp        |   12 ++++++++++++
 2 files changed, 43 insertions(+)


Index: llvm/lib/Transforms/Scalar/LowerPacked.cpp
diff -u llvm/lib/Transforms/Scalar/LowerPacked.cpp:1.6 llvm/lib/Transforms/Scalar/LowerPacked.cpp:1.7
--- llvm/lib/Transforms/Scalar/LowerPacked.cpp:1.6	Mon Dec 26 07:48:44 2005
+++ llvm/lib/Transforms/Scalar/LowerPacked.cpp	Tue Jan 10 13:05:05 2006
@@ -59,6 +59,10 @@
    /// @param SELI the select operator to convert
    void visitSelectInst(SelectInst& SELI);
 
+   /// @brief Lowers packed extractelement instructions.
+   /// @param EI the extractelement operator to convert
+   void visitExtractElementInst(ExtractElementInst& EI);
+
    /// This function asserts if the instruction is a PackedType but
    /// is handled by another function.
    ///
@@ -330,6 +334,33 @@
       Changed = true;
       instrsToRemove.push_back(&SELI);
    }
+}
+
+void LowerPacked::visitExtractElementInst(ExtractElementInst& EI)
+{
+  std::vector<Value*>& op0Vals = getValues(EI.getOperand(0));
+  const PackedType *PTy = cast<PackedType>(EI.getOperand(0)->getType());
+  Value *op1 = EI.getOperand(1);
+
+  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()));
+    for (unsigned i = 0; i < PTy->getNumElements(); ++i) {
+      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);
+    LoadInst *load = new LoadInst(GEP, EI.getName() + ".load", &EI);
+    EI.replaceAllUsesWith(load);
+  }
+
+  Changed = true;
+  instrsToRemove.push_back(&EI);
 }
 
 bool LowerPacked::runOnFunction(Function& F)


Index: llvm/lib/Transforms/Scalar/SCCP.cpp
diff -u llvm/lib/Transforms/Scalar/SCCP.cpp:1.125 llvm/lib/Transforms/Scalar/SCCP.cpp:1.126
--- llvm/lib/Transforms/Scalar/SCCP.cpp:1.125	Mon Sep 26 00:28:52 2005
+++ llvm/lib/Transforms/Scalar/SCCP.cpp	Tue Jan 10 13:05:05 2006
@@ -322,6 +322,7 @@
   void visitSelectInst(SelectInst &I);
   void visitBinaryOperator(Instruction &I);
   void visitShiftInst(ShiftInst &I) { visitBinaryOperator(I); }
+  void visitExtractElementInst(ExtractElementInst &I);
 
   // Instructions that cannot be folded away...
   void visitStoreInst     (Instruction &I);
@@ -726,6 +727,17 @@
     markConstant(IV, &I, ConstantExpr::get(I.getOpcode(), V1State.getConstant(),
                                            V2State.getConstant()));
   }
+}
+
+void SCCPSolver::visitExtractElementInst(ExtractElementInst &I) {
+  LatticeVal &ValState = getValueState(I.getOperand(0));
+  LatticeVal &IdxState = getValueState(I.getOperand(1));
+
+  if (ValState.isOverdefined() || IdxState.isOverdefined())
+    markOverdefined(&I);
+  else if(ValState.isConstant() && IdxState.isConstant())
+    markConstant(&I, ConstantExpr::getExtractElement(ValState.getConstant(),
+                                                     IdxState.getConstant()));
 }
 
 // Handle getelementptr instructions... if all operands are constants then we






More information about the llvm-commits mailing list