[llvm] r245365 - [InstSimplify] Don't assume getAggregateElement will succeed
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 19 13:56:15 PDT 2015
Is this a fix we should merge to 3.7?
On Tue, Aug 18, 2015 at 3:07 PM, David Majnemer via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: majnemer
> Date: Tue Aug 18 17:07:25 2015
> New Revision: 245365
>
> URL: http://llvm.org/viewvc/llvm-project?rev=245365&view=rev
> Log:
> [InstSimplify] Don't assume getAggregateElement will succeed
>
> It isn't always possible to get a value from getAggregateElement.
> This fixes PR24488.
>
> Modified:
> llvm/trunk/lib/Analysis/InstructionSimplify.cpp
> llvm/trunk/lib/Analysis/VectorUtils.cpp
> llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
>
> Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=245365&r1=245364&r2=245365&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
> +++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Aug 18 17:07:25 2015
> @@ -3578,11 +3578,6 @@ static Value *SimplifyExtractElementInst
> 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;
> }
>
> Modified: llvm/trunk/lib/Analysis/VectorUtils.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/VectorUtils.cpp?rev=245365&r1=245364&r2=245365&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/VectorUtils.cpp (original)
> +++ llvm/trunk/lib/Analysis/VectorUtils.cpp Tue Aug 18 17:07:25 2015
> @@ -398,10 +398,10 @@ Value *llvm::findScalarElement(Value *V,
>
> // 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;
>
> Modified: llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll?rev=245365&r1=245364&r2=245365&view=diff
> ==============================================================================
> --- llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll (original)
> +++ llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll Tue Aug 18 17:07:25 2015
> @@ -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]]
> +}
More information about the llvm-commits
mailing list