diff options
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 14 | 
1 files changed, 14 insertions, 0 deletions
| diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 170b47694af..bf287f2c680 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -8564,6 +8564,20 @@ Instruction *InstCombiner::visitZExt(ZExtInst &CI) {      }    } +  // zext(trunc(t) & C) -> (t & C)  if C is a mask. +  if (SrcI && SrcI->getOpcode() == Instruction::And && SrcI->hasOneUse()) +    if (ConstantInt *C = dyn_cast<ConstantInt>(SrcI->getOperand(1))) +      if (TruncInst *TI = dyn_cast<TruncInst>(SrcI->getOperand(0))) { +        Value *TI0 = TI->getOperand(0); +        if (TI0->getType() == CI.getType()) { +          unsigned TO = C->getValue().countTrailingOnes(); +          if (APIntOps::isMask(TO, C->getValue())) +            return +              BinaryOperator::Create(Instruction::And, TI0, +                                     ConstantExpr::getZExt(C, CI.getType())); +        } +      } +    return 0;  } | 

