[PATCH] D107770: [CallPromotion] Fix byval/inalloca handling
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 9 09:49:20 PDT 2021
aeubanks created this revision.
Herald added subscribers: wenlei, hiraditya.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
If the previously indirect call contained a byval/inalloca attribute but
the callee did not have the same attribute, we'd end up not updating the
call's type attribute.
Followup to D63842 <https://reviews.llvm.org/D63842>.
Fixes PR51397.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D107770
Files:
llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
llvm/test/Transforms/PGOProfile/mismatched-byval.ll
llvm/test/Transforms/PGOProfile/mismatched-inalloca.ll
Index: llvm/test/Transforms/PGOProfile/mismatched-inalloca.ll
===================================================================
--- /dev/null
+++ 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}
Index: llvm/test/Transforms/PGOProfile/mismatched-byval.ll
===================================================================
--- /dev/null
+++ 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}
Index: llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/CallPromotionUtils.cpp
+++ 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107770.365206.patch
Type: text/x-patch
Size: 4087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210809/73ce8280/attachment.bin>
More information about the llvm-commits
mailing list