diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 26c560cee2173..cebb6a96b1500 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -12544,8 +12544,13 @@ struct AAAddressSpaceImpl : public AAAddressSpace { // CGSCC if the AA is run on CGSCC instead of the entire module. if (!A.isRunOn(Inst->getFunction())) return true; - if (isa(Inst) || isa(Inst)) + if (isa(Inst)) MakeChange(Inst, const_cast(U)); + if (auto *SI = dyn_cast(Inst)) { + // We only make changes if the use is the pointer operand. + if (U.getOperandNo() == 1) + MakeChange(Inst, const_cast(U)); + } return true; }; diff --git a/llvm/test/Transforms/Attributor/address_space_info.ll b/llvm/test/Transforms/Attributor/address_space_info.ll index 076060a2763c2..d865ae1eae39b 100644 --- a/llvm/test/Transforms/Attributor/address_space_info.ll +++ b/llvm/test/Transforms/Attributor/address_space_info.ll @@ -20,8 +20,7 @@ define internal void @_Z12global_writePi(ptr noundef %p) #0 { ; CHECK-SAME: (ptr nofree noundef nonnull writeonly align 4 dereferenceable(8) [[P:%.*]]) #[[ATTR0:[0-9]+]] { ; CHECK-NEXT: entry: ; CHECK-NEXT: [[TMP0:%.*]] = addrspacecast ptr [[P]] to ptr addrspace(1) -; CHECK-NEXT: [[TMP1:%.*]] = addrspacecast ptr [[P]] to ptr addrspace(1) -; CHECK-NEXT: store ptr addrspace(1) [[TMP0]], ptr addrspace(1) [[TMP1]], align 4 +; CHECK-NEXT: store ptr [[P]], ptr addrspace(1) [[TMP0]], align 4 ; CHECK-NEXT: ret void ; entry: