From e3fb157234c40dfa2746dbb08edd8730cc4b78c4 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 10 Sep 2022 20:52:08 +0200 Subject: Vendor import of llvm-project branch release/15.x llvmorg-15.0.0-0-g4ba6a9c9f65b (aka 15.0.0 release). --- .../lib/Transforms/InstCombine/InstCombineCompares.cpp | 4 +--- llvm/lib/Transforms/Utils/LoopUtils.cpp | 5 ++++- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 12 ++++++++---- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 18 ++++++++---------- 4 files changed, 21 insertions(+), 18 deletions(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 158d2e8289e0..edbd4091d1d2 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2040,9 +2040,7 @@ Instruction *InstCombinerImpl::foldICmpMulConstant(ICmpInst &Cmp, NewC = ConstantInt::get( Mul->getType(), APIntOps::RoundingSDiv(C, *MulC, APInt::Rounding::DOWN)); - } - - if (Mul->hasNoUnsignedWrap()) { + } else if (Mul->hasNoUnsignedWrap()) { if (Pred == ICmpInst::ICMP_ULT || Pred == ICmpInst::ICMP_UGE) NewC = ConstantInt::get( Mul->getType(), diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index 349063dd5e89..bbba76a5c5ef 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1394,7 +1394,10 @@ int llvm::rewriteLoopExitValues(Loop *L, LoopInfo *LI, TargetLibraryInfo *TLI, // and next SCEV may errneously get smaller cost. // Collect all the candidate PHINodes to be rewritten. - RewritePhiSet.emplace_back(PN, i, ExitValue, Inst, HighCost); + Instruction *InsertPt = + (isa(Inst) || isa(Inst)) ? + &*Inst->getParent()->getFirstInsertionPt() : Inst; + RewritePhiSet.emplace_back(PN, i, ExitValue, InsertPt, HighCost); } } } diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 03087d8370d5..245f2d4e442a 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -89,10 +89,12 @@ static Value *convertStrToInt(CallInst *CI, StringRef &Str, Value *EndPtr, // Fail for an invalid base (required by POSIX). return nullptr; + // Current offset into the original string to reflect in EndPtr. + size_t Offset = 0; // Strip leading whitespace. - for (unsigned i = 0; i != Str.size(); ++i) - if (!isSpace((unsigned char)Str[i])) { - Str = Str.substr(i); + for ( ; Offset != Str.size(); ++Offset) + if (!isSpace((unsigned char)Str[Offset])) { + Str = Str.substr(Offset); break; } @@ -108,6 +110,7 @@ static Value *convertStrToInt(CallInst *CI, StringRef &Str, Value *EndPtr, if (Str.empty()) // Fail for a sign with nothing after it. return nullptr; + ++Offset; } // Set Max to the absolute value of the minimum (for signed), or @@ -127,6 +130,7 @@ static Value *convertStrToInt(CallInst *CI, StringRef &Str, Value *EndPtr, return nullptr; Str = Str.drop_front(2); + Offset += 2; Base = 16; } else if (Base == 0) @@ -167,7 +171,7 @@ static Value *convertStrToInt(CallInst *CI, StringRef &Str, Value *EndPtr, if (EndPtr) { // Store the pointer to the end. - Value *Off = B.getInt64(Str.size()); + Value *Off = B.getInt64(Offset + Str.size()); Value *StrBeg = CI->getArgOperand(0); Value *StrEnd = B.CreateInBoundsGEP(B.getInt8Ty(), StrBeg, Off, "endptr"); B.CreateStore(StrEnd, EndPtr); diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index d69d1e3d19f3..53c11c58f73d 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -4696,10 +4696,12 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, }; SmallVector SortedIndices; BasicBlock *BB = nullptr; + bool IsScatterVectorizeUserTE = + UserTreeIdx.UserTE && + UserTreeIdx.UserTE->State == TreeEntry::ScatterVectorize; bool AreAllSameInsts = (S.getOpcode() && allSameBlock(VL)) || - (S.OpValue->getType()->isPointerTy() && UserTreeIdx.UserTE && - UserTreeIdx.UserTE->State == TreeEntry::ScatterVectorize && + (S.OpValue->getType()->isPointerTy() && IsScatterVectorizeUserTE && VL.size() > 2 && all_of(VL, [&BB](Value *V) { @@ -4760,10 +4762,9 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, // Check that none of the instructions in the bundle are already in the tree. for (Value *V : VL) { - auto *I = dyn_cast(V); - if (!I) + if (!IsScatterVectorizeUserTE && !isa(V)) continue; - if (getTreeEntry(I)) { + if (getTreeEntry(V)) { LLVM_DEBUG(dbgs() << "SLP: The instruction (" << *V << ") is already in tree.\n"); if (TryToFindDuplicates(S)) @@ -5213,9 +5214,6 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, } } - bool IsScatterUser = - UserTreeIdx.UserTE && - UserTreeIdx.UserTE->State == TreeEntry::ScatterVectorize; // We don't combine GEPs with non-constant indexes. Type *Ty1 = VL0->getOperand(1)->getType(); for (Value *V : VL) { @@ -5223,9 +5221,9 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, if (!I) continue; auto *Op = I->getOperand(1); - if ((!IsScatterUser && !isa(Op)) || + if ((!IsScatterVectorizeUserTE && !isa(Op)) || (Op->getType() != Ty1 && - ((IsScatterUser && !isa(Op)) || + ((IsScatterVectorizeUserTE && !isa(Op)) || Op->getType()->getScalarSizeInBits() > DL->getIndexSizeInBits( V->getType()->getPointerAddressSpace())))) { -- cgit v1.2.3