Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f2da941

Browse filesBrowse files
committed
Analysis: Remove no-AssumptionCache path in getKnowledgeForValue
As requested in #138961 (comment)
1 parent 03d3e6d commit f2da941
Copy full SHA for f2da941

File tree

Expand file treeCollapse file tree

5 files changed

+24
-41
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+24
-41
lines changed

‎llvm/include/llvm/Analysis/AssumeBundleQueries.h

Copy file name to clipboardExpand all lines: llvm/include/llvm/Analysis/AssumeBundleQueries.h
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,18 +152,19 @@ RetainedKnowledge getKnowledgeFromUse(const Use *U,
152152
/// in AttrKinds and it matches the Filter.
153153
RetainedKnowledge getKnowledgeForValue(
154154
const Value *V, ArrayRef<Attribute::AttrKind> AttrKinds,
155-
AssumptionCache *AC = nullptr,
155+
AssumptionCache &AC,
156156
function_ref<bool(RetainedKnowledge, Instruction *,
157-
const CallBase::BundleOpInfo *)>
157+
const CallBase::BundleOpInfo *)>
158158
Filter = [](auto...) { return true; });
159159

160160
/// Return a valid Knowledge associated to the Value V if its Attribute kind is
161161
/// in AttrKinds and the knowledge is suitable to be used in the context of
162162
/// CtxI.
163-
RetainedKnowledge getKnowledgeValidInContext(
164-
const Value *V, ArrayRef<Attribute::AttrKind> AttrKinds,
165-
const Instruction *CtxI, const DominatorTree *DT = nullptr,
166-
AssumptionCache *AC = nullptr);
163+
RetainedKnowledge
164+
getKnowledgeValidInContext(const Value *V,
165+
ArrayRef<Attribute::AttrKind> AttrKinds,
166+
AssumptionCache &AC, const Instruction *CtxI,
167+
const DominatorTree *DT = nullptr);
167168

168169
/// This extracts the Knowledge from an element of an operand bundle.
169170
/// This is mostly for use in the assume builder.

‎llvm/lib/Analysis/AssumeBundleQueries.cpp

Copy file name to clipboardExpand all lines: llvm/lib/Analysis/AssumeBundleQueries.cpp
+12-30Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -157,51 +157,33 @@ llvm::getKnowledgeFromUse(const Use *U,
157157
RetainedKnowledge
158158
llvm::getKnowledgeForValue(const Value *V,
159159
ArrayRef<Attribute::AttrKind> AttrKinds,
160-
AssumptionCache *AC,
160+
AssumptionCache &AC,
161161
function_ref<bool(RetainedKnowledge, Instruction *,
162162
const CallBase::BundleOpInfo *)>
163163
Filter) {
164164
NumAssumeQueries++;
165-
if (AC) {
166-
for (AssumptionCache::ResultElem &Elem : AC->assumptionsFor(V)) {
167-
auto *II = cast_or_null<AssumeInst>(Elem.Assume);
168-
if (!II || Elem.Index == AssumptionCache::ExprResultIdx)
169-
continue;
170-
if (RetainedKnowledge RK = getKnowledgeFromBundle(
171-
*II, II->bundle_op_info_begin()[Elem.Index])) {
172-
if (V != RK.WasOn)
173-
continue;
174-
if (is_contained(AttrKinds, RK.AttrKind) &&
175-
Filter(RK, II, &II->bundle_op_info_begin()[Elem.Index])) {
176-
NumUsefullAssumeQueries++;
177-
return RK;
178-
}
179-
}
180-
}
181-
return RetainedKnowledge::none();
182-
}
183-
184-
if (!V->hasUseList())
185-
return RetainedKnowledge::none();
186-
187-
for (const auto &U : V->uses()) {
188-
CallInst::BundleOpInfo* Bundle = getBundleFromUse(&U);
189-
if (!Bundle)
165+
for (AssumptionCache::ResultElem &Elem : AC.assumptionsFor(V)) {
166+
auto *II = cast_or_null<AssumeInst>(Elem.Assume);
167+
if (!II || Elem.Index == AssumptionCache::ExprResultIdx)
190168
continue;
191-
if (RetainedKnowledge RK =
192-
getKnowledgeFromBundle(*cast<AssumeInst>(U.getUser()), *Bundle))
169+
if (RetainedKnowledge RK = getKnowledgeFromBundle(
170+
*II, II->bundle_op_info_begin()[Elem.Index])) {
171+
if (V != RK.WasOn)
172+
continue;
193173
if (is_contained(AttrKinds, RK.AttrKind) &&
194-
Filter(RK, cast<Instruction>(U.getUser()), Bundle)) {
174+
Filter(RK, II, &II->bundle_op_info_begin()[Elem.Index])) {
195175
NumUsefullAssumeQueries++;
196176
return RK;
197177
}
178+
}
198179
}
180+
199181
return RetainedKnowledge::none();
200182
}
201183

202184
RetainedKnowledge llvm::getKnowledgeValidInContext(
203185
const Value *V, ArrayRef<Attribute::AttrKind> AttrKinds,
204-
const Instruction *CtxI, const DominatorTree *DT, AssumptionCache *AC) {
186+
AssumptionCache &AC, const Instruction *CtxI, const DominatorTree *DT) {
205187
return getKnowledgeForValue(V, AttrKinds, AC,
206188
[&](auto, Instruction *I, auto) {
207189
return isValidAssumeForContext(I, CtxI, DT);

‎llvm/lib/Analysis/Loads.cpp

Copy file name to clipboardExpand all lines: llvm/lib/Analysis/Loads.cpp
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@ static bool isDereferenceableAndAlignedPointer(
174174
// information for values that cannot be freed in the function.
175175
// TODO: More precisely check if the pointer can be freed between assumption
176176
// and use.
177-
if (CtxI && !V->canBeFreed()) {
177+
if (CtxI && AC && !V->canBeFreed()) {
178178
/// Look through assumes to see if both dereferencability and alignment can
179179
/// be proven by an assume if needed.
180180
RetainedKnowledge AlignRK;
181181
RetainedKnowledge DerefRK;
182182
bool IsAligned = V->getPointerAlignment(DL) >= Alignment;
183183
if (getKnowledgeForValue(
184-
V, {Attribute::Dereferenceable, Attribute::Alignment}, AC,
184+
V, {Attribute::Dereferenceable, Attribute::Alignment}, *AC,
185185
[&](RetainedKnowledge RK, Instruction *Assume, auto) {
186186
if (!isValidAssumeForContext(Assume, CtxI, DT))
187187
return false;

‎llvm/lib/Analysis/ValueTracking.cpp

Copy file name to clipboardExpand all lines: llvm/lib/Analysis/ValueTracking.cpp
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8010,7 +8010,7 @@ static bool isGuaranteedNotToBeUndefOrPoison(
80108010
Dominator = Dominator->getIDom();
80118011
}
80128012

8013-
if (getKnowledgeValidInContext(V, {Attribute::NoUndef}, CtxI, DT, AC))
8013+
if (AC && getKnowledgeValidInContext(V, {Attribute::NoUndef}, *AC, CtxI, DT))
80148014
return true;
80158015

80168016
return false;

‎llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp

Copy file name to clipboardExpand all lines: llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ struct AssumeBuilderState {
114114
: M(M), InstBeingModified(I), AC(AC), DT(DT) {}
115115

116116
bool tryToPreserveWithoutAddingAssume(RetainedKnowledge RK) {
117-
if (!InstBeingModified || !RK.WasOn)
117+
if (!InstBeingModified || !RK.WasOn || !AC)
118118
return false;
119119
bool HasBeenPreserved = false;
120120
Use* ToUpdate = nullptr;
121121
getKnowledgeForValue(
122-
RK.WasOn, {RK.AttrKind}, AC,
122+
RK.WasOn, {RK.AttrKind}, *AC,
123123
[&](RetainedKnowledge RKOther, Instruction *Assume,
124124
const CallInst::BundleOpInfo *Bundle) {
125125
if (!isValidAssumeForContext(Assume, InstBeingModified, DT))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.