diff options
| author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2017-12-26 11:42:39 +0000 |
|---|---|---|
| committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2017-12-26 11:42:39 +0000 |
| commit | 79c2c2f08c8513be679b2ff8ad3a53b2db3343d9 (patch) | |
| tree | 46e1f1937503c165afa30cebd6ac7aa64ff0735a | |
| parent | c67d6b2da0a651a48408ca03ee2edc1bc9a3c29a (diff) | |
| download | bcm5719-llvm-79c2c2f08c8513be679b2ff8ad3a53b2db3343d9.tar.gz bcm5719-llvm-79c2c2f08c8513be679b2ff8ad3a53b2db3343d9.zip | |
[InstSimplify] Check for in range extraction index before calling APInt::getZExtValue()
Reduced from oss-fuzz #4768 test case
llvm-svn: 321454
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 5 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstSimplify/extract-element.ll | 13 |
2 files changed, 16 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 3ce1281743c..fac6a917dc9 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -3897,8 +3897,9 @@ static Value *SimplifyExtractElementInst(Value *Vec, Value *Idx, const SimplifyQ // 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 (auto *IdxC = dyn_cast<ConstantInt>(Idx)) - if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue())) - return Elt; + if (IdxC->getValue().ule(Vec->getType()->getVectorNumElements())) + if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue())) + return Elt; // An undef extract index can be arbitrarily chosen to be an out-of-range // index value, which would result in the instruction being undef. diff --git a/llvm/test/Transforms/InstSimplify/extract-element.ll b/llvm/test/Transforms/InstSimplify/extract-element.ll new file mode 100644 index 00000000000..8ee75a603cd --- /dev/null +++ b/llvm/test/Transforms/InstSimplify/extract-element.ll @@ -0,0 +1,13 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -instsimplify -S | FileCheck %s + +; Weird Types + +define i129 @vec_extract_negidx(<3 x i129> %a) { +; CHECK-LABEL: @vec_extract_negidx( +; CHECK-NEXT: [[E1:%.*]] = extractelement <3 x i129> [[A:%.*]], i129 -1 +; CHECK-NEXT: ret i129 [[E1]] +; + %E1 = extractelement <3 x i129> %a, i129 -1 + ret i129 %E1 +} |

