[llvm] r321454 - [InstSimplify] Check for in range extraction index before calling APInt::getZExtValue()
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 26 03:42:39 PST 2017
Author: rksimon
Date: Tue Dec 26 03:42:39 2017
New Revision: 321454
URL: http://llvm.org/viewvc/llvm-project?rev=321454&view=rev
Log:
[InstSimplify] Check for in range extraction index before calling APInt::getZExtValue()
Reduced from oss-fuzz #4768 test case
Added:
llvm/trunk/test/Transforms/InstSimplify/extract-element.ll
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=321454&r1=321453&r2=321454&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Dec 26 03:42:39 2017
@@ -3897,8 +3897,9 @@ static Value *SimplifyExtractElementInst
// 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.
Added: llvm/trunk/test/Transforms/InstSimplify/extract-element.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/extract-element.ll?rev=321454&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/extract-element.ll (added)
+++ llvm/trunk/test/Transforms/InstSimplify/extract-element.ll Tue Dec 26 03:42:39 2017
@@ -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
+}
More information about the llvm-commits
mailing list