[PATCH] D45308: [IPRA] Do not collect register usage information on functions that can be derefined

Kit Barton via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 4 19:51:25 PDT 2018


kbarton created this revision.
kbarton added reviewers: MatzeB, sanjoy, power-llvm-team.
Herald added subscribers: hiraditya, nemanjai.

Do not collect register usage information to be used by IPRA on functions that can be derefined. 
If it is possible for a function to be replaced at link time with another version of the function, that has been optimized differently, we cannot assume the reg mask will be correct. For a more indepth explanation of de-refinement, see https://reviews.llvm.org/D18634.

This patch checks the isDefinitionExact method on the function to ensure the function cannot be redefined. If the definition is not exact, do not refine the register usage information during the collection phase of IPRA.


https://reviews.llvm.org/D45308

Files:
  llvm/lib/CodeGen/RegUsageInfoCollector.cpp
  llvm/test/CodeGen/PowerPC/ipra-odr.ll


Index: llvm/test/CodeGen/PowerPC/ipra-odr.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/ipra-odr.ll
@@ -0,0 +1,30 @@
+; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -enable-ipra < %s | FileCheck %s
+;
+; Check that IPRA does not run and change register allocation in functions that
+; have callees that could be redefined at link time.
+
+ at x = local_unnamed_addr global i64 0, align 4
+
+; Function Attrs: norecurse nounwind
+define weak_odr void @bar(i64 signext %a, i64 signext %b) local_unnamed_addr {
+entry:
+b  %add = add nsw i64 %b, %a
+  store i64 %add, i64* @x, align 4
+  ret void
+}
+
+; CHECK-LABEL: @foo
+; CHECK: bl bar
+; CHECK: nop
+; CHECK: mr 3, {{[0-9]+}}
+; CHECK: mr 4, {{[0-9]+}}
+; CHECK: bl bar
+; CHECK: blr
+define signext i64 @foo(i64 signext %a, i64 signext %b) {
+entry:
+  call void @bar(i64 signext %a, i64 signext %b)
+  call void @bar(i64 signext %a, i64 signext %b)
+
+ret i64 0
+}
+
Index: llvm/lib/CodeGen/RegUsageInfoCollector.cpp
===================================================================
--- llvm/lib/CodeGen/RegUsageInfoCollector.cpp
+++ llvm/lib/CodeGen/RegUsageInfoCollector.cpp
@@ -97,6 +97,9 @@
 
   const Function &F = MF.getFunction();
 
+ if (!F.isDefinitionExact())
+    return false;
+
   PhysicalRegisterUsageInfo *PRUI = &getAnalysis<PhysicalRegisterUsageInfo>();
 
   PRUI->setTargetMachine(&TM);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45308.141100.patch
Type: text/x-patch
Size: 1430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180405/972489fa/attachment.bin>


More information about the llvm-commits mailing list