Skip to content

Commit 2ccbf92

Browse files
committed
InferAddressSpaces: Restore non-instruction user check
Fixes regression after 79658d6. We were missing test coverage for the nested constant expression case.
1 parent 2e9f3f3 commit 2ccbf92

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class InferAddressSpacesImpl {
241241
unsigned joinAddressSpaces(unsigned AS1, unsigned AS2) const;
242242

243243
unsigned getPredicatedAddrSpace(const Value &PtrV,
244-
const Instruction *UserCtxI) const;
244+
const Value *UserCtx) const;
245245

246246
public:
247247
InferAddressSpacesImpl(AssumptionCache &AC, const DominatorTree *DT,
@@ -910,8 +910,13 @@ void InferAddressSpacesImpl::inferAddressSpaces(
910910
}
911911
}
912912

913-
unsigned InferAddressSpacesImpl::getPredicatedAddrSpace(
914-
const Value &Ptr, const Instruction *UserCtxI) const {
913+
unsigned
914+
InferAddressSpacesImpl::getPredicatedAddrSpace(const Value &Ptr,
915+
const Value *UserCtx) const {
916+
const Instruction *UserCtxI = dyn_cast<Instruction>(UserCtx);
917+
if (!UserCtxI)
918+
return UninitializedAddressSpace;
919+
915920
const Value *StrippedPtr = Ptr.stripInBoundsOffsets();
916921
for (auto &AssumeVH : AC.assumptionsFor(StrippedPtr)) {
917922
if (!AssumeVH)
@@ -986,8 +991,7 @@ bool InferAddressSpacesImpl::updateAddressSpace(
986991
OperandAS = PtrOperand->getType()->getPointerAddressSpace();
987992
if (OperandAS == FlatAddrSpace) {
988993
// Check AC for assumption dominating V.
989-
unsigned AS =
990-
getPredicatedAddrSpace(*PtrOperand, &cast<Instruction>(V));
994+
unsigned AS = getPredicatedAddrSpace(*PtrOperand, &V);
991995
if (AS != UninitializedAddressSpace) {
992996
LLVM_DEBUG(dbgs()
993997
<< " deduce operand AS from the predicate addrspace "

llvm/test/Transforms/InferAddressSpaces/AMDGPU/basic.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ define i32 @atomicrmw_add_global_to_flat_preserve_amdgpu_md(ptr addrspace(1) %gl
190190
ret i32 %ret
191191
}
192192

193+
; Make sure there's no assert
194+
; CHECK-LABEL: @try_infer_getelementptr_constant_null(
195+
; CHECK-NEXT: %ce = getelementptr i8, ptr getelementptr inbounds (i8, ptr null, i64 8), i64 0
196+
define ptr @try_infer_getelementptr_constant_null() {
197+
%ce = getelementptr i8, ptr getelementptr inbounds (i8, ptr null, i64 8), i64 0
198+
ret ptr %ce
199+
}
200+
193201
attributes #0 = { nounwind }
194202

195203
!0 = !{}

0 commit comments

Comments
 (0)