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

Eric Christopher echristo at gmail.com
Fri Nov 30 14:14:42 PST 2012


+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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121130/2bb8459f/attachment.html>


More information about the llvm-commits mailing list