Skip to content

Commit b07bf16

Browse files
authored
[AssumptionCache] Add affected values for separate_storage (#76806)
Add the underlying object of both separate_storage arguments as affected values. This allows us to use assumptionsFor() in BasicAA, which will be more efficient if there are many assumes in the function.
1 parent c17af94 commit b07bf16

File tree

2 files changed

+27
-23
lines changed

2 files changed

+27
-23
lines changed

llvm/lib/Analysis/AssumptionCache.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/Analysis/AssumeBundleQueries.h"
1919
#include "llvm/Analysis/TargetTransformInfo.h"
20+
#include "llvm/Analysis/ValueTracking.h"
2021
#include "llvm/IR/BasicBlock.h"
2122
#include "llvm/IR/Function.h"
2223
#include "llvm/IR/InstrTypes.h"
@@ -77,9 +78,15 @@ findAffectedValues(CallBase *CI, TargetTransformInfo *TTI,
7778
};
7879

7980
for (unsigned Idx = 0; Idx != CI->getNumOperandBundles(); Idx++) {
80-
if (CI->getOperandBundleAt(Idx).Inputs.size() > ABA_WasOn &&
81-
CI->getOperandBundleAt(Idx).getTagName() != IgnoreBundleTag)
82-
AddAffected(CI->getOperandBundleAt(Idx).Inputs[ABA_WasOn], Idx);
81+
OperandBundleUse Bundle = CI->getOperandBundleAt(Idx);
82+
if (Bundle.getTagName() == "separate_storage") {
83+
assert(Bundle.Inputs.size() == 2 &&
84+
"separate_storage must have two args");
85+
AddAffected(getUnderlyingObject(Bundle.Inputs[0]), Idx);
86+
AddAffected(getUnderlyingObject(Bundle.Inputs[1]), Idx);
87+
} else if (Bundle.Inputs.size() > ABA_WasOn &&
88+
Bundle.getTagName() != IgnoreBundleTag)
89+
AddAffected(Bundle.Inputs[ABA_WasOn], Idx);
8390
}
8491

8592
Value *Cond = CI->getArgOperand(0), *A, *B;

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,28 +1544,25 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size,
15441544
return AliasResult::NoAlias;
15451545

15461546
if (CtxI && EnableSeparateStorageAnalysis) {
1547-
for (auto &AssumeVH : AC.assumptions()) {
1548-
if (!AssumeVH)
1547+
for (AssumptionCache::ResultElem &Elem : AC.assumptionsFor(O1)) {
1548+
if (!Elem || Elem.Index == AssumptionCache::ExprResultIdx)
15491549
continue;
15501550

1551-
AssumeInst *Assume = cast<AssumeInst>(AssumeVH);
1552-
1553-
for (unsigned Idx = 0; Idx < Assume->getNumOperandBundles(); Idx++) {
1554-
OperandBundleUse OBU = Assume->getOperandBundleAt(Idx);
1555-
if (OBU.getTagName() == "separate_storage") {
1556-
assert(OBU.Inputs.size() == 2);
1557-
const Value *Hint1 = OBU.Inputs[0].get();
1558-
const Value *Hint2 = OBU.Inputs[1].get();
1559-
// This is often a no-op; instcombine rewrites this for us. No-op
1560-
// getUnderlyingObject calls are fast, though.
1561-
const Value *HintO1 = getUnderlyingObject(Hint1);
1562-
const Value *HintO2 = getUnderlyingObject(Hint2);
1563-
1564-
if (((O1 == HintO1 && O2 == HintO2) ||
1565-
(O1 == HintO2 && O2 == HintO1)) &&
1566-
isValidAssumeForContext(Assume, CtxI, DT))
1567-
return AliasResult::NoAlias;
1568-
}
1551+
AssumeInst *Assume = cast<AssumeInst>(Elem);
1552+
OperandBundleUse OBU = Assume->getOperandBundleAt(Elem.Index);
1553+
if (OBU.getTagName() == "separate_storage") {
1554+
assert(OBU.Inputs.size() == 2);
1555+
const Value *Hint1 = OBU.Inputs[0].get();
1556+
const Value *Hint2 = OBU.Inputs[1].get();
1557+
// This is often a no-op; instcombine rewrites this for us. No-op
1558+
// getUnderlyingObject calls are fast, though.
1559+
const Value *HintO1 = getUnderlyingObject(Hint1);
1560+
const Value *HintO2 = getUnderlyingObject(Hint2);
1561+
1562+
if (((O1 == HintO1 && O2 == HintO2) ||
1563+
(O1 == HintO2 && O2 == HintO1)) &&
1564+
isValidAssumeForContext(Assume, CtxI, DT))
1565+
return AliasResult::NoAlias;
15691566
}
15701567
}
15711568
}

0 commit comments

Comments
 (0)