[llvm] ccaded2 - [Inliner] Prevent adding pointer attributes to non-pointer arguments (#115569)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 9 08:17:19 PST 2024
Author: Harald van Dijk
Date: 2024-11-09T16:17:16Z
New Revision: ccaded2b1d0d2cf3d8041baeeec9cfad632c9450
URL: https://github.com/llvm/llvm-project/commit/ccaded2b1d0d2cf3d8041baeeec9cfad632c9450
DIFF: https://github.com/llvm/llvm-project/commit/ccaded2b1d0d2cf3d8041baeeec9cfad632c9450.diff
LOG: [Inliner] Prevent adding pointer attributes to non-pointer arguments (#115569)
Fixes a crash seen after #114311
Added:
Modified:
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Transforms/Inline/arg-attr-propagation.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index a27cb4dd219c30..aa5e04d71657a7 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1465,7 +1465,7 @@ static void AddParamAndFnBasicAttributes(const CallBase &CB,
}
}
AL = AL.addParamAttributes(Context, I, NewAB);
- } else {
+ } else if (NewInnerCB->getArgOperand(I)->getType()->isPointerTy()) {
// Check if the underlying value for the parameter is an argument.
const Value *UnderlyingV =
getUnderlyingObject(InnerCB->getArgOperand(I));
@@ -1473,10 +1473,13 @@ static void AddParamAndFnBasicAttributes(const CallBase &CB,
if (!Arg)
continue;
ArgNo = Arg->getArgNo();
+ } else {
+ continue;
}
// If so, propagate its access attributes.
AL = AL.addParamAttributes(Context, I, ValidObjParamAttrs[ArgNo]);
+
// We can have conflicting attributes from the inner callsite and
// to-be-inlined callsite. In that case, choose the most
// restrictive.
diff --git a/llvm/test/Transforms/Inline/arg-attr-propagation.ll b/llvm/test/Transforms/Inline/arg-attr-propagation.ll
index 7b096539e7e1b1..fad6c7ced2edd2 100644
--- a/llvm/test/Transforms/Inline/arg-attr-propagation.ll
+++ b/llvm/test/Transforms/Inline/arg-attr-propagation.ll
@@ -76,3 +76,29 @@ define i32 @caller3(ptr dereferenceable(33) %t1) {
ret i32 %t2
}
+; Make sure that we don't propagate a pointer-only attribute to a vector of pointers.
+
+declare void @helper4(<4 x ptr> %ptr)
+
+define void @callee4(ptr readonly %ptr, <4 x i64> %idx) {
+; CHECK-LABEL: define {{[^@]+}}@callee4
+; CHECK-SAME: (ptr readonly [[PTR:%.*]], <4 x i64> [[IDX:%.*]]) {
+; CHECK-NEXT: [[PTRS:%.*]] = getelementptr inbounds i8, ptr [[PTR]], <4 x i64> [[IDX]]
+; CHECK-NEXT: call void @helper4(<4 x ptr> [[PTRS]])
+; CHECK-NEXT: ret void
+;
+ %ptrs = getelementptr inbounds i8, ptr %ptr, <4 x i64> %idx
+ call void @helper4(<4 x ptr> %ptrs)
+ ret void
+}
+
+define void @caller4(ptr readonly %ptr, <4 x i64> %idx) {
+; CHECK-LABEL: define {{[^@]+}}@caller4
+; CHECK-SAME: (ptr readonly [[PTR:%.*]], <4 x i64> [[IDX:%.*]]) {
+; CHECK-NEXT: [[PTRS_I:%.*]] = getelementptr inbounds i8, ptr [[PTR]], <4 x i64> [[IDX]]
+; CHECK-NEXT: call void @helper4(<4 x ptr> [[PTRS_I]])
+; CHECK-NEXT: ret void
+;
+ call void @callee4(ptr readonly %ptr, <4 x i64> %idx)
+ ret void
+}
More information about the llvm-commits
mailing list