diff options
| author | Chris Lattner <sabre@nondot.org> | 2007-04-09 01:37:55 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2007-04-09 01:37:55 +0000 |
| commit | a87c9f61149740ff3b27ec477befdfe6eb442965 (patch) | |
| tree | 8a58d2e26ad9864fdeec16137dbdfcb853648d14 /llvm/lib/Transforms/Scalar/InstructionCombining.cpp | |
| parent | e04c652f5db975ff00bcabc220b7a55ab155d7e3 (diff) | |
| download | bcm5719-llvm-a87c9f61149740ff3b27ec477befdfe6eb442965.tar.gz bcm5719-llvm-a87c9f61149740ff3b27ec477befdfe6eb442965.zip | |
Fix PR1304 and Transforms/InstCombine/2007-04-08-SingleEltVectorCrash.ll
llvm-svn: 35792
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 47f64992336..62f2b5afd02 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -8943,11 +8943,19 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) { // 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, |

