[PATCH] fix for bug 18319
    Nick Lewycky 
    nicholas at mxc.ca
       
    Tue Dec 24 16:45:08 PST 2013
    
    
  
On 12/24/2013 07:18 AM, Ilia Filippov wrote:
> Hello,
>
> Could somebody please review and commit my fix to bug
> http://llvm.org/bugs/show_bug.cgi?id=18319 ?
> (patch is attached).
>
> The fix handles the case of vector select constant expression containing
> "undef" values in ConstantFoldSelectInstruction function.
Index: lib/IR/ConstantFold.cpp
===================================================================
--- lib/IR/ConstantFold.cpp	(revision 197903)
+++ lib/IR/ConstantFold.cpp	(working copy)
@@ -706,9 +706,15 @@
      Type *Ty = IntegerType::get(CondV->getContext(), 32);
      for (unsigned i = 0, e = V1->getType()->getVectorNumElements(); i 
!= e;++i){
        ConstantInt *Cond = dyn_cast<ConstantInt>(CondV->getOperand(i));
-      if (Cond == 0) break;
-
-      Constant *V = Cond->isNullValue() ? V2 : V1;
+      Constant *V;
+      if (Cond == 0) {
+        if (isa<UndefValue>(CondV->getOperand(i)))
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.
There's some other logic missing here though. If 
cast<ConstantVector>(V1)->getOperand(n) is equal to 
cast<ConstantVector>(V2)->getOperand(n), then we don't care what Cond is 
at all, we should just pick that element.
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?
Nick
+          V = V2;
+        else
+          break;
+      }
+      else
+        V = Cond->isNullValue() ? V2 : V1;
        Constant *Res = ConstantExpr::getExtractElement(V, 
ConstantInt::get(Ty, i));
        Result.push_back(Res);
      }
    
    
More information about the llvm-commits
mailing list