<div dir="ltr">Here is an updated patch, please review</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/25 Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 12/24/2013 07:18 AM, Ilia Filippov wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
Could somebody please review and commit my fix to bug<br>
<a href="http://llvm.org/bugs/show_bug.cgi?id=18319" target="_blank">http://llvm.org/bugs/show_bug.<u></u>cgi?id=18319</a> ?<br>
(patch is attached).<br>
<br>
The fix handles the case of vector select constant expression containing<br>
"undef" values in ConstantFoldSelectInstruction function.<br>
</blockquote>
<br></div></div>
Index: lib/IR/ConstantFold.cpp<br>
==============================<u></u>==============================<u></u>=======<br>
--- lib/IR/ConstantFold.cpp     (revision 197903)<br>
+++ lib/IR/ConstantFold.cpp     (working copy)<br>
@@ -706,9 +706,15 @@<br>
     Type *Ty = IntegerType::get(CondV-><u></u>getContext(), 32);<br>
     for (unsigned i = 0, e = V1->getType()-><u></u>getVectorNumElements(); i != e;++i){<br>
       ConstantInt *Cond = dyn_cast<ConstantInt>(CondV-><u></u>getOperand(i));<br>
-      if (Cond == 0) break;<br>
-<br>
-      Constant *V = Cond->isNullValue() ? V2 : V1;<br>
+      Constant *V;<br>
+      if (Cond == 0) {<br>
+        if (isa<UndefValue>(CondV-><u></u>getOperand(i)))<br>
<br>
Instead of re-getting from CondV, make Cond a Constant* instead of a ConstantInt*, and have it do "if (!isa<ConstantInt>(Cond)) break;" after handling the undef case.<br>
<br>
There's some other logic missing here though. If cast<ConstantVector>(V1)-><u></u>getOperand(n) is equal to cast<ConstantVector>(V2)-><u></u>getOperand(n), then we don't care what Cond is at all, we should just pick that element.<br>

<br>
Since we're going to look at each element this way, why not check if one of the elements is better than the other (ie., is an undef) and then pick that element when the condition is undef?<br>
<br>
Nick<br>
<br>
+          V = V2;<br>
+        else<br>
+          break;<br>
+      }<br>
+      else<br>
+        V = Cond->isNullValue() ? V2 : V1;<br>
       Constant *Res = ConstantExpr::<u></u>getExtractElement(V, ConstantInt::get(Ty, i));<br>
       Result.push_back(Res);<br>
     }<br>
<br>
______________________________<u></u>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>