Skip to content

Commit a501d06

Browse files
authored
[Attributor] Only manifest pointer operand for StoreInst in AAAddressSpace (#65708)
`AAAddressSpace` currently only works for `LoadInst` and `StoreInst` currently. For `StoreInst`, the corresponding use can be the pointer operand, or value operand, or both. When it is used as value operand, it can prevent `AMDGPUPromoteAlloca` from optimization in certain cases. This patch changes the manifest method such that only pointer operand will be rewritten.
1 parent 31d4f06 commit a501d06

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12550,8 +12550,13 @@ struct AAAddressSpaceImpl : public AAAddressSpace {
1255012550
// CGSCC if the AA is run on CGSCC instead of the entire module.
1255112551
if (!A.isRunOn(Inst->getFunction()))
1255212552
return true;
12553-
if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst))
12553+
if (isa<LoadInst>(Inst))
1255412554
MakeChange(Inst, const_cast<Use &>(U));
12555+
if (auto *SI = dyn_cast<StoreInst>(Inst)) {
12556+
// We only make changes if the use is the pointer operand.
12557+
if (U.getOperandNo() == 1)
12558+
MakeChange(Inst, const_cast<Use &>(U));
12559+
}
1255512560
return true;
1255612561
};
1255712562

llvm/test/Transforms/Attributor/address_space_info.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ define internal void @_Z12global_writePi(ptr noundef %p) #0 {
2020
; CHECK-SAME: (ptr nofree noundef nonnull writeonly align 4 dereferenceable(8) [[P:%.*]]) #[[ATTR0:[0-9]+]] {
2121
; CHECK-NEXT: entry:
2222
; CHECK-NEXT: [[TMP0:%.*]] = addrspacecast ptr [[P]] to ptr addrspace(1)
23-
; CHECK-NEXT: [[TMP1:%.*]] = addrspacecast ptr [[P]] to ptr addrspace(1)
24-
; CHECK-NEXT: store ptr addrspace(1) [[TMP0]], ptr addrspace(1) [[TMP1]], align 4
23+
; CHECK-NEXT: store ptr [[P]], ptr addrspace(1) [[TMP0]], align 4
2524
; CHECK-NEXT: ret void
2625
;
2726
entry:

0 commit comments

Comments
 (0)