[llvm] 7a07b88 - [Attributor][FIX] Replace call site argument uses, not values
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 9 03:03:48 PDT 2022
Author: Johannes Doerfert
Date: 2022-06-09T12:00:26+02:00
New Revision: 7a07b88f37c090670daf17b77b6a747cffe6792e
URL: https://github.com/llvm/llvm-project/commit/7a07b88f37c090670daf17b77b6a747cffe6792e
DIFF: https://github.com/llvm/llvm-project/commit/7a07b88f37c090670daf17b77b6a747cffe6792e.diff
LOG: [Attributor][FIX] Replace call site argument uses, not values
We need to be careful replacing values as call site arguments
(IRPosition::IRP_CALL_SITE_ARGUMENT) is representing a use and not a
value. This patch replaces the interface to take a IR position instead
making it harder to misuse accidentally. It does not change our tests
right now but a follow up exposed the potential footgun.
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index ac1890a771409..81ee6d5b762f0 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -1589,11 +1589,17 @@ struct Attributor {
return true;
}
- /// Helper function to replace all uses of \p V with \p NV. Return true if
- /// there is any change. The flag \p ChangeDroppable indicates if dropppable
- /// uses should be changed too.
- bool changeValueAfterManifest(Value &V, Value &NV,
- bool ChangeDroppable = true) {
+ /// Helper function to replace all uses associated with \p IRP with \p NV.
+ /// Return true if there is any change. The flag \p ChangeDroppable indicates
+ /// if dropppable uses should be changed too.
+ bool changeAfterManifest(const IRPosition IRP, Value &NV,
+ bool ChangeDroppable = true) {
+ if (IRP.getPositionKind() == IRPosition::IRP_CALL_SITE_ARGUMENT) {
+ auto *CB = cast<CallBase>(IRP.getCtxI());
+ return changeUseAfterManifest(
+ CB->getArgOperandUse(IRP.getCallSiteArgNo()), NV);
+ }
+ Value &V = IRP.getAssociatedValue();
auto &Entry = ToBeChangedValues[&V];
Value *&CurNV = Entry.first;
if (CurNV && (CurNV->stripPointerCasts() == NV.stripPointerCasts() ||
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index ed87ecdde44d5..58f407db5d014 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -6259,7 +6259,7 @@ struct AAHeapToStackFunction final : public AAHeapToStack {
assert(InitVal &&
"Must be able to materialize initial memory state of allocation");
- A.changeValueAfterManifest(*AI.CB, *Alloca);
+ A.changeAfterManifest(IRPosition::inst(*AI.CB), *Alloca);
if (auto *II = dyn_cast<InvokeInst>(AI.CB)) {
auto *NBB = II->getNormalDest();
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 5c457ba83f898..99b996ad57ed1 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -2657,7 +2657,7 @@ struct AAICVTrackerCallSite : AAICVTracker {
if (!ReplVal.hasValue() || !ReplVal.getValue())
return ChangeStatus::UNCHANGED;
- A.changeValueAfterManifest(*getCtxI(), **ReplVal);
+ A.changeAfterManifest(IRPosition::inst(*getCtxI()), **ReplVal);
A.deleteAfterManifest(*getCtxI());
return ChangeStatus::CHANGED;
@@ -3054,7 +3054,7 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
"HeapToShared on allocation without alignment attribute");
SharedMem->setAlignment(MaybeAlign(Alignment));
- A.changeValueAfterManifest(*CB, *NewBuffer);
+ A.changeAfterManifest(IRPosition::callsite_returned(*CB), *NewBuffer);
A.deleteAfterManifest(*CB);
A.deleteAfterManifest(*FreeCalls.front());
@@ -4496,7 +4496,7 @@ struct AAFoldRuntimeCallCallSiteReturned : AAFoldRuntimeCall {
if (SimplifiedValue.hasValue() && SimplifiedValue.getValue()) {
Instruction &I = *getCtxI();
- A.changeValueAfterManifest(I, **SimplifiedValue);
+ A.changeAfterManifest(IRPosition::inst(I), **SimplifiedValue);
A.deleteAfterManifest(I);
CallBase *CB = dyn_cast<CallBase>(&I);
More information about the llvm-commits
mailing list