llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-llvm-transforms Author: Pablo Reble (reble) <details> <summary>Changes</summary> The arguments and the return value of a function that might be replaced by another definition, e.g. a `linkonce_odr` function, are never updated. But some AAs still took known information from its body in `initialize`, which was kept and propagated to the callers: the uses of the arguments (`followUsesInMBEC`), assumptions (`getAttrsFromAssumes`), and the returned values (`AANonNull::isImpliedByIR`). Add `Attributor::canUseBodyFor` and skip the body for the interface of such functions, as FunctionAttrs does. Depends on #<!-- -->243247. Assisted-by: Claude Opus 5.5 --- Full diff: https://github.com/llvm/llvm-project/pull/243310.diff 5 Files Affected: - (modified) llvm/include/llvm/Transforms/IPO/Attributor.h (+11) - (modified) llvm/lib/Transforms/IPO/Attributor.cpp (+3) - (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+6) - (modified) llvm/test/Transforms/Attributor/align.ll (+3-3) - (modified) llvm/test/Transforms/Attributor/nonnull.ll (+12-22) ``````````diff diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h index 41f2c362281a4..625e52b2691e0 100644 --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -1843,6 +1843,17 @@ struct Attributor { (Configuration.IPOAmendableCB && Configuration.IPOAmendableCB(F)); } + /// Return true if the body of the associated function can be used to derive + /// information for \p IRP. + /// + /// That is not the case for the interface (function, argument and return + /// positions) of a function that might be replaced by another definition, + /// e.g. a linkonce_odr function. + bool canUseBodyFor(const IRPosition &IRP) { + return !IRP.isFnInterfaceKind() || + isFunctionIPOAmendable(*IRP.getAssociatedFunction()); + } + /// Return whether attributes can participate in fixed-point deduction. bool isDuringDeduction() const { return Phase == AttributorPhase::SEEDING || diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 1ead8c32d1cf7..c0d5438e6a4c8 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -1053,6 +1053,9 @@ bool Attributor::getAttrsFromAssumes(const IRPosition &IRP, if (A2K.empty()) return false; + if (!canUseBodyFor(IRP)) + return false; + LLVMContext &Ctx = AssociatedValue.getContext(); unsigned AttrsSize = Attrs.size(); auto EIt = Explorer->begin(IRP.getCtxI()), diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index b8744f99efeac..d6e67f9989d87 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -625,6 +625,9 @@ static void followUsesInContext(AAType &AA, Attributor &A, template <class AAType, typename StateType = typename AAType::StateType> static void followUsesInMBEC(AAType &AA, Attributor &A, StateType &S, Instruction &CtxI) { + if (!A.canUseBodyFor(AA.getIRPosition())) + return; + const Value &Val = AA.getIRPosition().getAssociatedValue(); if (isa<ConstantData>(Val)) return; @@ -2398,6 +2401,9 @@ bool AANonNull::isImpliedByIR(Attributor &A, const IRPosition &IRP, if (A.hasAttr(IRP, AttrKinds, IgnoreSubsumingPositions, Attribute::NonNull)) return true; + if (!A.canUseBodyFor(IRP)) + return false; + DominatorTree *DT = nullptr; AssumptionCache *AC = nullptr; InformationCache &InfoCache = A.getInfoCache(); diff --git a/llvm/test/Transforms/Attributor/align.ll b/llvm/test/Transforms/Attributor/align.ll index e3d355ae8a4cd..4009c661312d3 100644 --- a/llvm/test/Transforms/Attributor/align.ll +++ b/llvm/test/Transforms/Attributor/align.ll @@ -1219,7 +1219,7 @@ declare void @implicit_cast_callee(i64) ; derived from its body. define linkonce_odr void @align_from_load_non_exact(ptr %a) { ; CHECK-LABEL: define {{[^@]+}}@align_from_load_non_exact -; CHECK-SAME: (ptr align 8 [[A:%.*]]) { +; CHECK-SAME: (ptr [[A:%.*]]) { ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[A]], align 8 ; CHECK-NEXT: ret void ; @@ -1229,8 +1229,8 @@ define linkonce_odr void @align_from_load_non_exact(ptr %a) { define void @call_align_from_load_non_exact(ptr %a) { ; CHECK-LABEL: define {{[^@]+}}@call_align_from_load_non_exact -; CHECK-SAME: (ptr align 8 [[A:%.*]]) { -; CHECK-NEXT: call void @align_from_load_non_exact(ptr align 8 [[A]]) +; CHECK-SAME: (ptr [[A:%.*]]) { +; CHECK-NEXT: call void @align_from_load_non_exact(ptr [[A]]) ; CHECK-NEXT: ret void ; call void @align_from_load_non_exact(ptr %a) diff --git a/llvm/test/Transforms/Attributor/nonnull.ll b/llvm/test/Transforms/Attributor/nonnull.ll index 1f751fed990fb..1228ce0503343 100644 --- a/llvm/test/Transforms/Attributor/nonnull.ll +++ b/llvm/test/Transforms/Attributor/nonnull.ll @@ -1642,7 +1642,7 @@ if.else: ; arguments and return value must not be derived from its body. define linkonce_odr ptr @nonnull_return_from_load_non_exact(ptr %p) { ; CHECK-LABEL: define {{[^@]+}}@nonnull_return_from_load_non_exact -; CHECK-SAME: (ptr align 4 [[P:%.*]]) { +; CHECK-SAME: (ptr [[P:%.*]]) { ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P]], align 4 ; CHECK-NEXT: ret ptr [[P]] ; @@ -1652,8 +1652,8 @@ define linkonce_odr ptr @nonnull_return_from_load_non_exact(ptr %p) { define ptr @call_nonnull_return_from_load_non_exact(ptr %p) { ; CHECK-LABEL: define {{[^@]+}}@call_nonnull_return_from_load_non_exact -; CHECK-SAME: (ptr align 4 [[P:%.*]]) { -; CHECK-NEXT: [[R:%.*]] = call nonnull ptr @nonnull_return_from_load_non_exact(ptr align 4 [[P]]) +; CHECK-SAME: (ptr [[P:%.*]]) { +; CHECK-NEXT: [[R:%.*]] = call ptr @nonnull_return_from_load_non_exact(ptr [[P]]) ; CHECK-NEXT: ret ptr [[R]] ; %r = call ptr @nonnull_return_from_load_non_exact(ptr %p) @@ -1673,7 +1673,7 @@ define linkonce_odr ptr @nonnull_return_from_assume_non_exact(ptr %p) { define ptr @call_nonnull_return_from_assume_non_exact(ptr %p) { ; CHECK-LABEL: define {{[^@]+}}@call_nonnull_return_from_assume_non_exact ; CHECK-SAME: (ptr [[P:%.*]]) { -; CHECK-NEXT: [[R:%.*]] = call nonnull ptr @nonnull_return_from_assume_non_exact(ptr [[P]]) +; CHECK-NEXT: [[R:%.*]] = call ptr @nonnull_return_from_assume_non_exact(ptr [[P]]) ; CHECK-NEXT: ret ptr [[R]] ; %r = call ptr @nonnull_return_from_assume_non_exact(ptr %p) @@ -1681,30 +1681,20 @@ define ptr @call_nonnull_return_from_assume_non_exact(ptr %p) { } define linkonce_odr void @align_from_assume_non_exact(ptr %a) { -; TUNIT-LABEL: define {{[^@]+}}@align_from_assume_non_exact -; TUNIT-SAME: (ptr align 16 [[A:%.*]]) { -; TUNIT-NEXT: call void @llvm.assume(i1 noundef true) [ "align"(ptr [[A]], i64 16) ] -; TUNIT-NEXT: ret void -; -; CGSCC-LABEL: define {{[^@]+}}@align_from_assume_non_exact -; CGSCC-SAME: (ptr [[A:%.*]]) { -; CGSCC-NEXT: call void @llvm.assume(i1 noundef true) [ "align"(ptr [[A]], i64 16) ] -; CGSCC-NEXT: ret void +; CHECK-LABEL: define {{[^@]+}}@align_from_assume_non_exact +; CHECK-SAME: (ptr [[A:%.*]]) { +; CHECK-NEXT: call void @llvm.assume(i1 noundef true) [ "align"(ptr [[A]], i64 16) ] +; CHECK-NEXT: ret void ; call void @llvm.assume(i1 true) [ "align"(ptr %a, i64 16) ] ret void } define void @call_align_from_assume_non_exact(ptr %a) { -; TUNIT-LABEL: define {{[^@]+}}@call_align_from_assume_non_exact -; TUNIT-SAME: (ptr align 16 [[A:%.*]]) { -; TUNIT-NEXT: call void @align_from_assume_non_exact(ptr align 16 [[A]]) -; TUNIT-NEXT: ret void -; -; CGSCC-LABEL: define {{[^@]+}}@call_align_from_assume_non_exact -; CGSCC-SAME: (ptr [[A:%.*]]) { -; CGSCC-NEXT: call void @align_from_assume_non_exact(ptr [[A]]) -; CGSCC-NEXT: ret void +; CHECK-LABEL: define {{[^@]+}}@call_align_from_assume_non_exact +; CHECK-SAME: (ptr [[A:%.*]]) { +; CHECK-NEXT: call void @align_from_assume_non_exact(ptr [[A]]) +; CHECK-NEXT: ret void ; call void @align_from_assume_non_exact(ptr %a) ret void `````````` </details> https://github.com/llvm/llvm-project/pull/243310 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
