[llvm-commits] [llvm] r169043 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Evan Cheng evan.cheng at apple.com
Fri Nov 30 15:30:25 PST 2012


I second Eric's comments. Please use early exits.

Thanks,

Evan

On Nov 30, 2012, at 2:14 PM, Eric Christopher <echristo at gmail.com> wrote:

> 
> 
> +static void detectLog2OfHalf(Value *&Op, Value *&Y, IntrinsicInst *&Log2) {
> +   if (Op->hasOneUse()) {
> +    if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Op)) {
> +      if (II->getIntrinsicID() == Intrinsic::log2 &&
> +          II->hasUnsafeAlgebra()) {
> +        Log2 = II;
> +        Value *OpLog2Of = II->getArgOperand(0);
> +        if (OpLog2Of->hasOneUse()) {
> +          if (Instruction *I = dyn_cast<Instruction>(OpLog2Of)) {
> +            if (I->getOpcode() == Instruction::FMul &&
> +                I->hasUnsafeAlgebra()) {
> +              ConstantFP *CFP = dyn_cast<ConstantFP>(I->getOperand(0));
> +              if (CFP && CFP->isExactlyValue(0.5)) {
> +                Y = I->getOperand(1);
> +              } else {
> +                CFP = dyn_cast<ConstantFP>(I->getOperand(1));
> +                if (CFP && CFP->isExactlyValue(0.5)) {
> +                  Y = I->getOperand(0);
> +                }
> +              }
> +            }
> +          }
> +        }
> +      }
> +    }
> +  }
> +}
> +
> 
> Trivially fwiw,
> 
> if (!Op->hasOneUse()) return false;
> if (!isa<IntrinsicInst>(Op)) return false;
> 
> and just change it to return true/false if you've managed to do something or not.
> 
> -eric 
> _______________________________________________
> 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/20121130/1c456d0d/attachment.html>


More information about the llvm-commits mailing list