[llvm] 2ccbf92 - InferAddressSpaces: Restore non-instruction user check

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 15 04:55:17 PDT 2024


Author: Matt Arsenault
Date: 2024-08-15T15:55:09+04:00
New Revision: 2ccbf92f878e385ab0067e2f767e39b295906a47

URL: https://github.com/llvm/llvm-project/commit/2ccbf92f878e385ab0067e2f767e39b295906a47
DIFF: https://github.com/llvm/llvm-project/commit/2ccbf92f878e385ab0067e2f767e39b295906a47.diff

LOG: InferAddressSpaces: Restore non-instruction user check

Fixes regression after 79658d65c3c7a075382b74d81e74714e2ea9bd2d.
We were missing test coverage for the nested constant expression
case.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
    llvm/test/Transforms/InferAddressSpaces/AMDGPU/basic.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
index 0c8aee8a494c03..3e3e5bfe2d6332 100644
--- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -241,7 +241,7 @@ class InferAddressSpacesImpl {
   unsigned joinAddressSpaces(unsigned AS1, unsigned AS2) const;
 
   unsigned getPredicatedAddrSpace(const Value &PtrV,
-                                  const Instruction *UserCtxI) const;
+                                  const Value *UserCtx) const;
 
 public:
   InferAddressSpacesImpl(AssumptionCache &AC, const DominatorTree *DT,
@@ -910,8 +910,13 @@ void InferAddressSpacesImpl::inferAddressSpaces(
   }
 }
 
-unsigned InferAddressSpacesImpl::getPredicatedAddrSpace(
-    const Value &Ptr, const Instruction *UserCtxI) const {
+unsigned
+InferAddressSpacesImpl::getPredicatedAddrSpace(const Value &Ptr,
+                                               const Value *UserCtx) const {
+  const Instruction *UserCtxI = dyn_cast<Instruction>(UserCtx);
+  if (!UserCtxI)
+    return UninitializedAddressSpace;
+
   const Value *StrippedPtr = Ptr.stripInBoundsOffsets();
   for (auto &AssumeVH : AC.assumptionsFor(StrippedPtr)) {
     if (!AssumeVH)
@@ -986,8 +991,7 @@ bool InferAddressSpacesImpl::updateAddressSpace(
           OperandAS = PtrOperand->getType()->getPointerAddressSpace();
           if (OperandAS == FlatAddrSpace) {
             // Check AC for assumption dominating V.
-            unsigned AS =
-                getPredicatedAddrSpace(*PtrOperand, &cast<Instruction>(V));
+            unsigned AS = getPredicatedAddrSpace(*PtrOperand, &V);
             if (AS != UninitializedAddressSpace) {
               LLVM_DEBUG(dbgs()
                          << "  deduce operand AS from the predicate addrspace "

diff  --git a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/basic.ll b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/basic.ll
index e6f26aeb98b141..eb39684a98b5f5 100644
--- a/llvm/test/Transforms/InferAddressSpaces/AMDGPU/basic.ll
+++ b/llvm/test/Transforms/InferAddressSpaces/AMDGPU/basic.ll
@@ -190,6 +190,14 @@ define i32 @atomicrmw_add_global_to_flat_preserve_amdgpu_md(ptr addrspace(1) %gl
   ret i32 %ret
 }
 
+; Make sure there's no assert
+; CHECK-LABEL: @try_infer_getelementptr_constant_null(
+; CHECK-NEXT: %ce = getelementptr i8, ptr getelementptr inbounds (i8, ptr null, i64 8), i64 0
+define ptr @try_infer_getelementptr_constant_null() {
+  %ce = getelementptr i8, ptr getelementptr inbounds (i8, ptr null, i64 8), i64 0
+  ret ptr %ce
+}
+
 attributes #0 = { nounwind }
 
 !0 = !{}


        


More information about the llvm-commits mailing list