diff options
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 2 | ||||
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 19 | ||||
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineInternal.h | 2 | 
3 files changed, 19 insertions, 4 deletions
| diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 8d9933b..92fca90 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -3496,7 +3496,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {        if (isPowerOf2_64(AlignMask + 1)) {          uint64_t Offset = 0;          match(A, m_Add(m_Value(A), m_ConstantInt(Offset))); -        if (match(A, m_PtrToInt(m_Value(A)))) { +        if (match(A, m_PtrToIntOrAddr(m_Value(A)))) {            /// Note: this doesn't preserve the offset information but merges            /// offset and alignment.            /// TODO: we can generate a GEP instead of merging the alignment with diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index f939e7a..614c6eb 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -2148,7 +2148,7 @@ Instruction *InstCombinerImpl::visitIntToPtr(IntToPtrInst &CI) {    return nullptr;  } -Value *InstCombinerImpl::foldPtrToIntOfGEP(Type *IntTy, Value *Ptr) { +Value *InstCombinerImpl::foldPtrToIntOrAddrOfGEP(Type *IntTy, Value *Ptr) {    // Look through chain of one-use GEPs.    Type *PtrTy = Ptr->getType();    SmallVector<GEPOperator *> GEPs; @@ -2210,7 +2210,7 @@ Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {        Mask->getType() == Ty)      return BinaryOperator::CreateAnd(Builder.CreatePtrToInt(Ptr, Ty), Mask); -  if (Value *V = foldPtrToIntOfGEP(Ty, SrcOp)) +  if (Value *V = foldPtrToIntOrAddrOfGEP(Ty, SrcOp))      return replaceInstUsesWith(CI, V);    Value *Vec, *Scalar, *Index; @@ -2228,6 +2228,21 @@ Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {  }  Instruction *InstCombinerImpl::visitPtrToAddr(PtrToAddrInst &CI) { +  Value *SrcOp = CI.getPointerOperand(); +  Type *Ty = CI.getType(); + +  // (ptrtoaddr (ptrmask P, M)) +  //    -> (and (ptrtoaddr P), M) +  // This is generally beneficial as `and` is better supported than `ptrmask`. +  Value *Ptr, *Mask; +  if (match(SrcOp, m_OneUse(m_Intrinsic<Intrinsic::ptrmask>(m_Value(Ptr), +                                                            m_Value(Mask)))) && +      Mask->getType() == Ty) +    return BinaryOperator::CreateAnd(Builder.CreatePtrToAddr(Ptr), Mask); + +  if (Value *V = foldPtrToIntOrAddrOfGEP(Ty, SrcOp)) +    return replaceInstUsesWith(CI, V); +    // FIXME: Implement variants of ptrtoint folds.    return commonCastTransforms(CI);  } diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 9c75d9a..d85e4f7 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -700,7 +700,7 @@ public:    /// folded operation.    void PHIArgMergedDebugLoc(Instruction *Inst, PHINode &PN); -  Value *foldPtrToIntOfGEP(Type *IntTy, Value *Ptr); +  Value *foldPtrToIntOrAddrOfGEP(Type *IntTy, Value *Ptr);    Instruction *foldGEPICmp(GEPOperator *GEPLHS, Value *RHS, CmpPredicate Cond,                             Instruction &I);    Instruction *foldSelectICmp(CmpPredicate Pred, SelectInst *SI, Value *RHS, | 
