aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-09-10 18:52:08 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-09-10 18:52:08 +0000
commite3fb157234c40dfa2746dbb08edd8730cc4b78c4 (patch)
treec95a6e213a999204b7ad635fb3fde0ae2f60e56b /llvm/lib/Transforms
parent677727e8296a802385345db6fa65e68223f4597a (diff)
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp4
-rw-r--r--llvm/lib/Transforms/Utils/LoopUtils.cpp5
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp12
-rw-r--r--llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp18
4 files changed, 21 insertions, 18 deletions
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<PHINode>(Inst) || isa<LandingPadInst>(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<Value *> VL, unsigned Depth,
};
SmallVector<unsigned> 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<Value *> 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<Instruction>(V);
- if (!I)
+ if (!IsScatterVectorizeUserTE && !isa<Instruction>(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<Value *> 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<Value *> VL, unsigned Depth,
if (!I)
continue;
auto *Op = I->getOperand(1);
- if ((!IsScatterUser && !isa<ConstantInt>(Op)) ||
+ if ((!IsScatterVectorizeUserTE && !isa<ConstantInt>(Op)) ||
(Op->getType() != Ty1 &&
- ((IsScatterUser && !isa<ConstantInt>(Op)) ||
+ ((IsScatterVectorizeUserTE && !isa<ConstantInt>(Op)) ||
Op->getType()->getScalarSizeInBits() >
DL->getIndexSizeInBits(
V->getType()->getPointerAddressSpace())))) {