Skip to content

[AssumptionCache] Add affected values for separate_storage #76806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions llvm/lib/Analysis/AssumptionCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/AssumeBundleQueries.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstrTypes.h"
Expand Down Expand Up @@ -77,9 +78,15 @@ findAffectedValues(CallBase *CI, TargetTransformInfo *TTI,
};

for (unsigned Idx = 0; Idx != CI->getNumOperandBundles(); Idx++) {
if (CI->getOperandBundleAt(Idx).Inputs.size() > ABA_WasOn &&
CI->getOperandBundleAt(Idx).getTagName() != IgnoreBundleTag)
AddAffected(CI->getOperandBundleAt(Idx).Inputs[ABA_WasOn], Idx);
OperandBundleUse Bundle = CI->getOperandBundleAt(Idx);
if (Bundle.getTagName() == "separate_storage") {
assert(Bundle.Inputs.size() == 2 &&
"separate_storage must have two args");
AddAffected(getUnderlyingObject(Bundle.Inputs[0]), Idx);
AddAffected(getUnderlyingObject(Bundle.Inputs[1]), Idx);
} else if (Bundle.Inputs.size() > ABA_WasOn &&
Bundle.getTagName() != IgnoreBundleTag)
AddAffected(Bundle.Inputs[ABA_WasOn], Idx);
}

Value *Cond = CI->getArgOperand(0), *A, *B;
Expand Down
37 changes: 17 additions & 20 deletions llvm/lib/Analysis/BasicAliasAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,28 +1544,25 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
return AliasResult::NoAlias;

if (CtxI && EnableSeparateStorageAnalysis) {
for (auto &AssumeVH : AC.assumptions()) {
if (!AssumeVH)
for (AssumptionCache::ResultElem &Elem : AC.assumptionsFor(O1)) {
if (!Elem || Elem.Index == AssumptionCache::ExprResultIdx)
continue;

AssumeInst *Assume = cast<AssumeInst>(AssumeVH);

for (unsigned Idx = 0; Idx < Assume->getNumOperandBundles(); Idx++) {
OperandBundleUse OBU = Assume->getOperandBundleAt(Idx);
if (OBU.getTagName() == "separate_storage") {
assert(OBU.Inputs.size() == 2);
const Value *Hint1 = OBU.Inputs[0].get();
const Value *Hint2 = OBU.Inputs[1].get();
// This is often a no-op; instcombine rewrites this for us. No-op
// getUnderlyingObject calls are fast, though.
const Value *HintO1 = getUnderlyingObject(Hint1);
const Value *HintO2 = getUnderlyingObject(Hint2);

if (((O1 == HintO1 && O2 == HintO2) ||
(O1 == HintO2 && O2 == HintO1)) &&
isValidAssumeForContext(Assume, CtxI, DT))
return AliasResult::NoAlias;
}
AssumeInst *Assume = cast<AssumeInst>(Elem);
OperandBundleUse OBU = Assume->getOperandBundleAt(Elem.Index);
if (OBU.getTagName() == "separate_storage") {
assert(OBU.Inputs.size() == 2);
const Value *Hint1 = OBU.Inputs[0].get();
const Value *Hint2 = OBU.Inputs[1].get();
// This is often a no-op; instcombine rewrites this for us. No-op
// getUnderlyingObject calls are fast, though.
const Value *HintO1 = getUnderlyingObject(Hint1);
const Value *HintO2 = getUnderlyingObject(Hint2);

if (((O1 == HintO1 && O2 == HintO2) ||
(O1 == HintO2 && O2 == HintO1)) &&
isValidAssumeForContext(Assume, CtxI, DT))
return AliasResult::NoAlias;
}
}
}
Expand Down