[PATCH] fix for bug 18319

Ilia Filippov ili.filippov at gmail.com
Fri Dec 27 06:45:59 PST 2013


Here is an updated patch, please review


2013/12/25 Nick Lewycky <nicholas at mxc.ca>

> 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);
>      }
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131227/2a12b1e3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix_18319.patch
Type: application/octet-stream
Size: 1320 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20131227/2a12b1e3/attachment.obj>


More information about the llvm-commits mailing list