<div dir="ltr">Yes, I think we should.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 19, 2015 at 1:56 PM, Hans Wennborg <span dir="ltr"><<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Is this a fix we should merge to 3.7?<br>
<div class="HOEnZb"><div class="h5"><br>
On Tue, Aug 18, 2015 at 3:07 PM, David Majnemer via llvm-commits<br>
<<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
> Author: majnemer<br>
> Date: Tue Aug 18 17:07:25 2015<br>
> New Revision: 245365<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=245365&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=245365&view=rev</a><br>
> Log:<br>
> [InstSimplify] Don't assume getAggregateElement will succeed<br>
><br>
> It isn't always possible to get a value from getAggregateElement.<br>
> This fixes PR24488.<br>
><br>
> Modified:<br>
> llvm/trunk/lib/Analysis/InstructionSimplify.cpp<br>
> llvm/trunk/lib/Analysis/VectorUtils.cpp<br>
> llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll<br>
><br>
> Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=245365&r1=245364&r2=245365&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=245365&r1=245364&r2=245365&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Aug 18 17:07:25 2015<br>
> @@ -3578,11 +3578,6 @@ static Value *SimplifyExtractElementInst<br>
> unsigned IndexVal = IdxC->getZExtValue();<br>
> unsigned VectorWidth = Vec->getType()->getVectorNumElements();<br>
><br>
> - // If this is extracting an invalid index, turn this into undef, to avoid<br>
> - // crashing the code below.<br>
> - if (IndexVal >= VectorWidth)<br>
> - return UndefValue::get(Vec->getType()->getVectorElementType());<br>
> -<br>
> if (Value *Elt = findScalarElement(Vec, IndexVal))<br>
> return Elt;<br>
> }<br>
><br>
> Modified: llvm/trunk/lib/Analysis/VectorUtils.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/VectorUtils.cpp?rev=245365&r1=245364&r2=245365&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/VectorUtils.cpp?rev=245365&r1=245364&r2=245365&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/lib/Analysis/VectorUtils.cpp (original)<br>
> +++ llvm/trunk/lib/Analysis/VectorUtils.cpp Tue Aug 18 17:07:25 2015<br>
> @@ -398,10 +398,10 @@ Value *llvm::findScalarElement(Value *V,<br>
><br>
> // Extract a value from a vector add operation with a constant zero.<br>
> Value *Val = nullptr; Constant *Con = nullptr;<br>
> - if (match(V, m_Add(m_Value(Val), m_Constant(Con)))) {<br>
> - if (Con->getAggregateElement(EltNo)->isNullValue())<br>
> - return findScalarElement(Val, EltNo);<br>
> - }<br>
> + if (match(V, m_Add(m_Value(Val), m_Constant(Con))))<br>
> + if (Constant *Elt = Con->getAggregateElement(EltNo))<br>
> + if (Elt->isNullValue())<br>
> + return findScalarElement(Val, EltNo);<br>
><br>
> // Otherwise, we don't know.<br>
> return nullptr;<br>
><br>
> Modified: llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll?rev=245365&r1=245364&r2=245365&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll?rev=245365&r1=245364&r2=245365&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll (original)<br>
> +++ llvm/trunk/test/Transforms/InstSimplify/2011-09-05-InsertExtractValue.ll Tue Aug 18 17:07:25 2015<br>
> @@ -36,3 +36,13 @@ define i32 @test3(i32 %a, float %b) {<br>
> ; CHECK-LABEL: @test3(<br>
> ; CHECK: ret i32 %a<br>
> }<br>
> +<br>
> +define i8 @test4(<8 x i8> %V) {<br>
> + %add = add <8 x i8> %V, bitcast (double 0x319BEB8FD172E36 to <8 x i8>)<br>
> + %extract = extractelement <8 x i8> %add, i32 6<br>
> + ret i8 %extract<br>
> +; CHECK-LABEL: @test4(<br>
> +; CHECK: %[[add:.*]] = add <8 x i8> %V, bitcast (<1 x double> <double 0x319BEB8FD172E36> to <8 x i8>)<br>
> +; CHECK-NEXT: %[[extract:.*]] = extractelement <8 x i8> %[[add]], i32 6<br>
> +; CHECK-NEXT: ret i8 %[[extract]]<br>
> +}<br>
</div></div></blockquote></div><br></div>