diff options
| author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2017-01-11 00:57:54 +0000 | 
|---|---|---|
| committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2017-01-11 00:57:54 +0000 | 
| commit | 8260666d11906435a4656efd15309f36b7f801c6 (patch) | |
| tree | 29a0d977b3fc2de075ae53f0e69b0e40026beece /llvm/lib/Analysis | |
| parent | c253c70abd96a4ce1ceffe6c0517f219d1cbd994 (diff) | |
| download | bcm5719-llvm-8260666d11906435a4656efd15309f36b7f801c6.tar.gz bcm5719-llvm-8260666d11906435a4656efd15309f36b7f801c6.zip | |
InstSimplify: Refactor function to use more switches
llvm-svn: 291634
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 89 | 
1 files changed, 51 insertions, 38 deletions
| diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 73dcd713416..796e6e44498 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -3583,7 +3583,7 @@ static Value *simplifySelectBitTest(Value *TrueVal, Value *FalseVal, Value *X,          *Y == *C)        return TrueWhenUnset ? TrueVal : FalseVal;    } -   +    return nullptr;  } @@ -3595,7 +3595,7 @@ static Value *simplifySelectWithFakeICmpEq(Value *CmpLHS, Value *TrueVal,    unsigned BitWidth = TrueVal->getType()->getScalarSizeInBits();    if (!BitWidth)      return nullptr; -   +    APInt MinSignedValue;    Value *X;    if (match(CmpLHS, m_Trunc(m_Value(X))) && (X == TrueVal || X == FalseVal)) { @@ -4252,14 +4252,36 @@ static Value *SimplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd,                                  const Query &Q, unsigned MaxRecurse) {    Intrinsic::ID IID = F->getIntrinsicID();    unsigned NumOperands = std::distance(ArgBegin, ArgEnd); -  Type *ReturnType = F->getReturnType(); + +  // Unary Ops +  if (NumOperands == 1) { +    // Perform idempotent optimizations +    if (IsIdempotent(IID)) { +      if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(*ArgBegin)) { +        if (II->getIntrinsicID() == IID) +          return II; +      } +    } + +    switch (IID) { +    case Intrinsic::fabs: { +      if (SignBitMustBeZero(*ArgBegin, Q.TLI)) +        return *ArgBegin; +    } +    default: +      return nullptr; +    } +  }    // Binary Ops    if (NumOperands == 2) {      Value *LHS = *ArgBegin;      Value *RHS = *(ArgBegin + 1); -    if (IID == Intrinsic::usub_with_overflow || -        IID == Intrinsic::ssub_with_overflow) { +    Type *ReturnType = F->getReturnType(); + +    switch (IID) { +    case Intrinsic::usub_with_overflow: +    case Intrinsic::ssub_with_overflow: {        // X - X -> { 0, false }        if (LHS == RHS)          return Constant::getNullValue(ReturnType); @@ -4268,17 +4290,19 @@ static Value *SimplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd,        // undef - X -> undef        if (isa<UndefValue>(LHS) || isa<UndefValue>(RHS))          return UndefValue::get(ReturnType); -    } -    if (IID == Intrinsic::uadd_with_overflow || -        IID == Intrinsic::sadd_with_overflow) { +      return nullptr; +    } +    case Intrinsic::uadd_with_overflow: +    case Intrinsic::sadd_with_overflow: {        // X + undef -> undef        if (isa<UndefValue>(RHS))          return UndefValue::get(ReturnType); -    } -    if (IID == Intrinsic::umul_with_overflow || -        IID == Intrinsic::smul_with_overflow) { +      return nullptr; +    } +    case Intrinsic::umul_with_overflow: +    case Intrinsic::smul_with_overflow: {        // X * 0 -> { 0, false }        if (match(RHS, m_Zero()))          return Constant::getNullValue(ReturnType); @@ -4286,45 +4310,34 @@ static Value *SimplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd,        // X * undef -> { 0, false }        if (match(RHS, m_Undef()))          return Constant::getNullValue(ReturnType); -    } -    if (IID == Intrinsic::load_relative && isa<Constant>(LHS) && -        isa<Constant>(RHS)) -      return SimplifyRelativeLoad(cast<Constant>(LHS), cast<Constant>(RHS), -                                  Q.DL); +      return nullptr; +    } +    case Intrinsic::load_relative: { +      Constant *C0 = dyn_cast<Constant>(LHS); +      Constant *C1 = dyn_cast<Constant>(RHS); +      if (C0 && C1) +        return SimplifyRelativeLoad(C0, C1, Q.DL); +      return nullptr; +    } +    default: +      return nullptr; +    }    }    // Simplify calls to llvm.masked.load.* -  if (IID == Intrinsic::masked_load) { +  switch (IID) { +  case Intrinsic::masked_load: {      Value *MaskArg = ArgBegin[2];      Value *PassthruArg = ArgBegin[3];      // If the mask is all zeros or undef, the "passthru" argument is the result.      if (maskIsAllZeroOrUndef(MaskArg))        return PassthruArg; +    return nullptr;    } - -  // Perform idempotent optimizations -  if (!IsIdempotent(IID)) +  default:      return nullptr; - -  // Unary Ops -  if (NumOperands == 1) { -    if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(*ArgBegin)) { -      if (II->getIntrinsicID() == IID) -        return II; -    } - -    switch (IID) { -    case Intrinsic::fabs: { -      if (SignBitMustBeZero(*ArgBegin, Q.TLI)) -        return *ArgBegin; -    } -    default: -      break; -    }    } - -  return nullptr;  }  template <typename IterTy> | 

