Skip to content

Commit

Permalink
InferAddressSpaces: Make getPredicatedAddrSpace less confusing (llvm#…
Browse files Browse the repository at this point in the history
…104052)

This takes a pointer value and the user instruction. Name them as
such, and remove the null check which should be dead.
  • Loading branch information
arsenm authored Aug 15, 2024
1 parent 43ffe2e commit 79658d6
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class InferAddressSpacesImpl {
SmallVectorImpl<const Use *> *PoisonUsesToFix) const;
unsigned joinAddressSpaces(unsigned AS1, unsigned AS2) const;

unsigned getPredicatedAddrSpace(const Value &V, Value *Opnd) const;
unsigned getPredicatedAddrSpace(const Value &PtrV,
const Instruction *UserCtxI) const;

public:
InferAddressSpacesImpl(AssumptionCache &AC, const DominatorTree *DT,
Expand Down Expand Up @@ -909,18 +910,14 @@ void InferAddressSpacesImpl::inferAddressSpaces(
}
}

unsigned InferAddressSpacesImpl::getPredicatedAddrSpace(const Value &V,
Value *Opnd) const {
const Instruction *I = dyn_cast<Instruction>(&V);
if (!I)
return UninitializedAddressSpace;

Opnd = Opnd->stripInBoundsOffsets();
for (auto &AssumeVH : AC.assumptionsFor(Opnd)) {
unsigned InferAddressSpacesImpl::getPredicatedAddrSpace(
const Value &Ptr, const Instruction *UserCtxI) const {
const Value *StrippedPtr = Ptr.stripInBoundsOffsets();
for (auto &AssumeVH : AC.assumptionsFor(StrippedPtr)) {
if (!AssumeVH)
continue;
CallInst *CI = cast<CallInst>(AssumeVH);
if (!isValidAssumeForContext(CI, I, DT))
if (!isValidAssumeForContext(CI, UserCtxI, DT))
continue;

const Value *Ptr;
Expand Down Expand Up @@ -989,7 +986,8 @@ bool InferAddressSpacesImpl::updateAddressSpace(
OperandAS = PtrOperand->getType()->getPointerAddressSpace();
if (OperandAS == FlatAddrSpace) {
// Check AC for assumption dominating V.
unsigned AS = getPredicatedAddrSpace(V, PtrOperand);
unsigned AS =
getPredicatedAddrSpace(*PtrOperand, &cast<Instruction>(V));
if (AS != UninitializedAddressSpace) {
LLVM_DEBUG(dbgs()
<< " deduce operand AS from the predicate addrspace "
Expand Down

0 comments on commit 79658d6

Please sign in to comment.