1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[InstSimplify] Don't assume getAggregateElement will succeed

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

llvm-svn: 245365
This commit is contained in:
David Majnemer 2015-08-18 22:07:25 +00:00
parent 6bbbc3b755
commit 729f29ab40
3 changed files with 14 additions and 9 deletions

View File

@ -3578,11 +3578,6 @@ static Value *SimplifyExtractElementInst(Value *Vec, Value *Idx, const Query &,
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))
return Elt;
}

View File

@ -398,10 +398,10 @@ Value *llvm::findScalarElement(Value *V, unsigned EltNo) {
// Extract a value from a vector add operation with a constant zero.
Value *Val = nullptr; Constant *Con = nullptr;
if (match(V, m_Add(m_Value(Val), m_Constant(Con)))) {
if (Con->getAggregateElement(EltNo)->isNullValue())
return findScalarElement(Val, EltNo);
}
if (match(V, m_Add(m_Value(Val), m_Constant(Con))))
if (Constant *Elt = Con->getAggregateElement(EltNo))
if (Elt->isNullValue())
return findScalarElement(Val, EltNo);
// Otherwise, we don't know.
return nullptr;

View File

@ -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]]
}