diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp --- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp +++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp @@ -487,11 +487,15 @@ // Remove any incompatible attributes for the argument. AttrBuilder ArgAttrs(CallerPAL.getParamAttributes(ArgNo)); ArgAttrs.remove(AttributeFuncs::typeIncompatible(FormalTy)); + ArgAttrs.removeAttribute(Attribute::ByVal); + ArgAttrs.removeAttribute(Attribute::InAlloca); // If byval is used, this must be a pointer type, and the byval type must // match the element type. Update it if present. - if (ArgAttrs.getByValType()) + if (Callee->getParamByValType(ArgNo)) ArgAttrs.addByValAttr(Callee->getParamByValType(ArgNo)); + if (Callee->getParamInAllocaType(ArgNo)) + ArgAttrs.addByValAttr(Callee->getParamInAllocaType(ArgNo)); NewArgAttrs.push_back(AttributeSet::get(Ctx, ArgAttrs)); AttributeChanged = true; diff --git a/llvm/test/Transforms/PGOProfile/mismatched-byval.ll b/llvm/test/Transforms/PGOProfile/mismatched-byval.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/PGOProfile/mismatched-byval.ll @@ -0,0 +1,33 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -passes=pgo-icall-prom -profile-summary-hot-count=10 -S < %s | FileCheck %s + +define void @a(i8* %0) !prof !0 { +; CHECK-LABEL: @a( +; CHECK-NEXT: ret void +; + ret void +} + +define void @b(void (i64*)** %v, i64* %p) !prof !1 { +; CHECK-LABEL: @b( +; CHECK-NEXT: [[A:%.*]] = load void (i64*)*, void (i64*)** [[V:%.*]], align 8 +; CHECK-NEXT: [[TMP1:%.*]] = icmp eq void (i64*)* [[A]], bitcast (void (i8*)* @a to void (i64*)*) +; CHECK-NEXT: br i1 [[TMP1]], label [[IF_TRUE_DIRECT_TARG:%.*]], label [[IF_FALSE_ORIG_INDIRECT:%.*]], !prof [[PROF2:![0-9]+]] +; CHECK: if.true.direct_targ: +; CHECK-NEXT: [[TMP2:%.*]] = bitcast i64* [[P:%.*]] to i8* +; CHECK-NEXT: call void @a(i8* [[TMP2]]) +; CHECK-NEXT: br label [[IF_END_ICP:%.*]] +; CHECK: if.false.orig_indirect: +; CHECK-NEXT: call void [[A]](i64* byval(i64) [[P]]) +; CHECK-NEXT: br label [[IF_END_ICP]] +; CHECK: if.end.icp: +; CHECK-NEXT: ret void +; + %a = load void (i64*)*, void (i64*)** %v + call void %a(i64* byval(i64) %p), !prof !2 + ret void +} + +!0 = !{!"function_entry_count", i64 36} +!1 = !{!"function_entry_count", i64 1} +!2 = !{!"VP", i32 0, i64 18, i64 12157170054180749580, i64 18} diff --git a/llvm/test/Transforms/PGOProfile/mismatched-inalloca.ll b/llvm/test/Transforms/PGOProfile/mismatched-inalloca.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/PGOProfile/mismatched-inalloca.ll @@ -0,0 +1,33 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -passes=pgo-icall-prom -profile-summary-hot-count=10 -S < %s | FileCheck %s + +define void @a(i8* %0) !prof !0 { +; CHECK-LABEL: @a( +; CHECK-NEXT: ret void +; + ret void +} + +define void @b(void (i64*)** %v, i64* %p) !prof !1 { +; CHECK-LABEL: @b( +; CHECK-NEXT: [[A:%.*]] = load void (i64*)*, void (i64*)** [[V:%.*]], align 8 +; CHECK-NEXT: [[TMP1:%.*]] = icmp eq void (i64*)* [[A]], bitcast (void (i8*)* @a to void (i64*)*) +; CHECK-NEXT: br i1 [[TMP1]], label [[IF_TRUE_DIRECT_TARG:%.*]], label [[IF_FALSE_ORIG_INDIRECT:%.*]], !prof [[PROF2:![0-9]+]] +; CHECK: if.true.direct_targ: +; CHECK-NEXT: [[TMP2:%.*]] = bitcast i64* [[P:%.*]] to i8* +; CHECK-NEXT: call void @a(i8* [[TMP2]]) +; CHECK-NEXT: br label [[IF_END_ICP:%.*]] +; CHECK: if.false.orig_indirect: +; CHECK-NEXT: call void [[A]](i64* inalloca(i64) [[P]]) +; CHECK-NEXT: br label [[IF_END_ICP]] +; CHECK: if.end.icp: +; CHECK-NEXT: ret void +; + %a = load void (i64*)*, void (i64*)** %v + call void %a(i64* inalloca(i64) %p), !prof !2 + ret void +} + +!0 = !{!"function_entry_count", i64 36} +!1 = !{!"function_entry_count", i64 1} +!2 = !{!"VP", i32 0, i64 18, i64 12157170054180749580, i64 18}