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

Chris Lattner sabre at nondot.org
Sun Apr 8 18:38:12 PDT 2007



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.736 -> 1.737
---
Log message:

Fix PR1304: http://llvm.org/PR1304  and Transforms/InstCombine/2007-04-08-SingleEltVectorCrash.ll


---
Diffs of the changes:  (+10 -2)

 InstructionCombining.cpp |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.736 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.737
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.736	Sun Apr  8 20:11:16 2007
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sun Apr  8 20:37:55 2007
@@ -8943,11 +8943,19 @@
   // If extracting a specified index from the vector, see if we can recursively
   // find a previously computed scalar that was inserted into the vector.
   if (ConstantInt *IdxC = dyn_cast<ConstantInt>(EI.getOperand(1))) {
+    unsigned IndexVal = IdxC->getZExtValue();
+    unsigned VectorWidth = 
+      cast<VectorType>(EI.getOperand(0)->getType())->getNumElements();
+      
+    // If this is extracting an invalid index, turn this into undef, to avoid
+    // crashing the code below.
+    if (IndexVal >= VectorWidth)
+      return ReplaceInstUsesWith(EI, UndefValue::get(EI.getType()));
+    
     // This instruction only demands the single element from the input vector.
     // If the input vector has a single use, simplify it based on this use
     // property.
-    uint64_t IndexVal = IdxC->getZExtValue();
-    if (EI.getOperand(0)->hasOneUse()) {
+    if (EI.getOperand(0)->hasOneUse() && VectorWidth != 1) {
       uint64_t UndefElts;
       if (Value *V = SimplifyDemandedVectorElts(EI.getOperand(0),
                                                 1 << IndexVal,






More information about the llvm-commits mailing list