diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2013-06-01 20:51:31 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2013-06-01 20:51:31 +0000 |
commit | e4546cb71e14baa0cde8f85a12cfa8b2d44fe708 (patch) | |
tree | 16c65db3f1487fe99a4fb6f91ad8b4880e231fec /lib/Transforms | |
parent | a0b34d6c4ab05d0c04905e2aff0c9e6b879908ff (diff) | |
download | llvm-e4546cb71e14baa0cde8f85a12cfa8b2d44fe708.tar.gz llvm-e4546cb71e14baa0cde8f85a12cfa8b2d44fe708.tar.bz2 llvm-e4546cb71e14baa0cde8f85a12cfa8b2d44fe708.tar.xz |
When determining the new index for an insertelement, we may not assume that an
index greater than the size of the vector is invalid. The shuffle may be
shrinking the size of the vector. Fixes a crash!
Also drop the maximum recursion depth of the safety check for this
optimization to five.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183080 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineVectorOps.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index 53fcb7154e..c76aa4c2e6 100644 --- a/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -497,7 +497,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) { /// Return true if we can evaluate the specified expression tree if the vector /// elements were shuffled in a different order. static bool CanEvaluateShuffled(Value *V, ArrayRef<int> Mask, - unsigned Depth = 100) { + unsigned Depth = 5) { // We can always reorder the elements of a constant. if (isa<Constant>(V)) return true; @@ -718,19 +718,21 @@ InstCombiner::EvaluateInDifferentElementOrder(Value *V, ArrayRef<int> Mask) { } case Instruction::InsertElement: { int Element = cast<ConstantInt>(I->getOperand(2))->getLimitedValue(); - if (Element < 0 || Element >= (int)Mask.size()) { - // Such instructions are valid and exhibit undefined behaviour. - return UndefValue::get(I->getType()); - } // The insertelement was inserting at Element. Figure out which element // that becomes after shuffling. The answer is guaranteed to be unique // by CanEvaluateShuffled. + bool Found = false; int Index = 0; - for (int e = Mask.size(); Index != e; ++Index) - if (Mask[Index] == Element) + for (int e = Mask.size(); Index != e; ++Index) { + if (Mask[Index] == Element) { + Found = true; break; + } + } + if (!Found) + return UndefValue::get(I->getType()); Value *V = EvaluateInDifferentElementOrder(I->getOperand(0), Mask); return InsertElementInst::Create(V, I->getOperand(1), Builder->getInt32(Index), "", I); |