[PATCH] SelectionDAG: fold (fp_to_u/sint (u/sint_to_fp val)) when possible

Mehdi Amini mehdi.amini at apple.com
Wed Feb 11 18:01:28 PST 2015


> On Feb 11, 2015, at 3:54 PM, Eric Christopher <echristo at gmail.com> wrote:
> 
> 
> 
> On Wed Feb 11 2015 at 3:52:06 PM Mehdi Amini <mehdi.amini at apple.com <mailto:mehdi.amini at apple.com>> wrote:
> +  Instruction *OpI = cast<Instruction>(FI.getOperand(0));
> +  if (!isa<UIToFPInst>(OpI) && !isa<SIToFPInst>(OpI))
> +    return nullptr;
> 
> You are using isa<>() on the result of an unsafe cast, it makes me nervous and I don’t know if it is safe this way.
> 
> 
> if (Instruction *Op1 = dyn_cast<Instruction>(FI.getOperand(0)) &&
>     ...)
> 
> should work?

I don’t think it is possible in C++.
You would need to add parenthesis around the assignment (precedence of assignment is lower than the one of logical operators), and if you do that the declaration is no longer valid.

And the dyn_cast is a spurious check anyway, to be able to replace it with a cast, you need to do it after the sanity check:

auto &Op = FI.getOperand(0);
if (!isa<UIToFPInst>(Op) && !isa<SIToFPInst>(Op))
  return nullptr;
Instruction *OpI = cast<Instruction>(Op);


— 
Mehdi



> 
> -eric
>  
> +        return new SExtInst(OpI->getOperand(0), FITy);
> +      else
> 
> You didn’t fix this.
> 
>> Mehdi
> 
> 
> > On Feb 11, 2015, at 3:39 PM, Fiona Glaser <fglaser at apple.com <mailto:fglaser at apple.com>> wrote:
> >
> > Patch updated based on comments.
> >
> > Fiona
> >
> > <floatcvtfold.diff>
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu <mailto:llvm-commits at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits <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/20150211/6441f321/attachment.html>


More information about the llvm-commits mailing list