Commit bcbf19f9 authored by Hans Wennborg's avatar Hans Wennborg
Browse files

Merging r245365 and r245369:

------------------------------------------------------------------------
r245365 | majnemer | 2015-08-18 15:07:25 -0700 (Tue, 18 Aug 2015) | 4 lines

[InstSimplify] Don't assume getAggregateElement will succeed

It isn't always possible to get a value from getAggregateElement.
This fixes PR24488.
------------------------------------------------------------------------

------------------------------------------------------------------------
r245369 | majnemer | 2015-08-18 15:18:22 -0700 (Tue, 18 Aug 2015) | 3 lines

[InstSimplify] Remove unused variable

No functionality change is intended.
------------------------------------------------------------------------

llvm-svn: 245572
parent 69272ee8
Loading
Loading
Loading
Loading
+2 −11
Original line number Diff line number Diff line
@@ -3574,18 +3574,9 @@ static Value *SimplifyExtractElementInst(Value *Vec, Value *Idx, const Query &,

  // 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)) {
    unsigned IndexVal = IdxC->getZExtValue();
    unsigned VectorWidth = Vec->getType()->getVectorNumElements();

    // If this is extracting an invalid index, turn this into undef, to avoid
    // crashing the code below.
    if (IndexVal >= VectorWidth)
      return UndefValue::get(Vec->getType()->getVectorElementType());

    if (Value *Elt = findScalarElement(Vec, IndexVal))
  if (auto *IdxC = dyn_cast<ConstantInt>(Idx))
    if (Value *Elt = findScalarElement(Vec, IdxC->getZExtValue()))
      return Elt;
  }

  return nullptr;
}
+3 −2
Original line number Diff line number Diff line
@@ -402,7 +402,8 @@ llvm::Value *llvm::findScalarElement(llvm::Value *V, unsigned EltNo) {
  if (match(V,
            llvm::PatternMatch::m_Add(llvm::PatternMatch::m_Value(Val),
                                      llvm::PatternMatch::m_Constant(Con)))) {
    if (Con->getAggregateElement(EltNo)->isNullValue())
    if (Constant *Elt = Con->getAggregateElement(EltNo))
      if (Elt->isNullValue())
        return findScalarElement(Val, EltNo);
  }

+10 −0
Original line number Diff line number Diff line
@@ -36,3 +36,13 @@ define i32 @test3(i32 %a, float %b) {
; CHECK-LABEL: @test3(
; CHECK: ret i32 %a
}

define i8 @test4(<8 x i8> %V) {
  %add     = add <8 x i8> %V, bitcast (double 0x319BEB8FD172E36 to <8 x i8>)
  %extract = extractelement <8 x i8> %add, i32 6
  ret i8 %extract
; CHECK-LABEL: @test4(
; CHECK: %[[add:.*]] = add <8 x i8> %V, bitcast (<1 x double> <double 0x319BEB8FD172E36> to <8 x i8>)
; CHECK-NEXT: %[[extract:.*]] = extractelement <8 x i8> %[[add]], i32 6
; CHECK-NEXT: ret i8 %[[extract]]
}