[llvm] r366557 - [IPRA] Don't rely on non-exact function definitions

Oliver Stannard via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 19 02:59:26 PDT 2019


Author: ostannard
Date: Fri Jul 19 02:59:26 2019
New Revision: 366557

URL: http://llvm.org/viewvc/llvm-project?rev=366557&view=rev
Log:
[IPRA] Don't rely on non-exact function definitions

If a function definition is not exact, then the linker could select a
differently-compiled version of it, which could use different registers.

https://reviews.llvm.org/D64909

Added:
    llvm/trunk/test/CodeGen/ARM/ipra-exact-definition.ll
Modified:
    llvm/trunk/lib/CodeGen/RegUsageInfoPropagate.cpp

Modified: llvm/trunk/lib/CodeGen/RegUsageInfoPropagate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegUsageInfoPropagate.cpp?rev=366557&r1=366556&r2=366557&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegUsageInfoPropagate.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegUsageInfoPropagate.cpp Fri Jul 19 02:59:26 2019
@@ -130,7 +130,11 @@ bool RegUsageInfoPropagation::runOnMachi
       };
 
       if (const Function *F = findCalledFunction(M, MI)) {
-        UpdateRegMask(*F);
+        if (F->isDefinitionExact()) {
+          UpdateRegMask(*F);
+        } else {
+          LLVM_DEBUG(dbgs() << "Function definition is not exact\n");
+        }
       } else {
         LLVM_DEBUG(dbgs() << "Failed to find call target function\n");
       }

Added: llvm/trunk/test/CodeGen/ARM/ipra-exact-definition.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/ipra-exact-definition.ll?rev=366557&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/ipra-exact-definition.ll (added)
+++ llvm/trunk/test/CodeGen/ARM/ipra-exact-definition.ll Fri Jul 19 02:59:26 2019
@@ -0,0 +1,44 @@
+; RUN: llc -mtriple armv7a--none-eabi < %s -enable-ipra | FileCheck %s
+
+; A linkone_odr function (the same applies to available_externally, linkonce,
+; weak, common, extern_weak and weak_odr) could be replaced with a
+; differently-compiled version of the same source at link time, which might use
+; different registers, so we can't do IPRA on it.
+define linkonce_odr void @leaf_linkonce_odr() {
+entry:
+  ret void
+}
+define void @test_linkonce_odr() {
+; CHECK-LABEL: test_linkonce_odr:
+entry:
+; CHECK: ASM1: r3
+; CHECK: mov   [[TEMP:r[0-9]+]], r3
+; CHECK: bl    leaf_linkonce_odr
+; CHECK: mov   r3, [[TEMP]]
+; CHECK: ASM2: r3
+  %0 = tail call i32 asm sideeffect "// ASM1: $0", "={r3},0"(i32 undef)
+  tail call void @leaf_linkonce_odr()
+  %1 = tail call i32 asm sideeffect "// ASM2: $0", "={r3},0"(i32 %0)
+  ret void
+}
+
+; This function has external linkage (the same applies to private, internal and
+; appending), so the version we see here is guaranteed to be the version
+; selected by the linker, so we can do IPRA.
+define external void @leaf_external() {
+entry:
+  ret void
+}
+define void @test_external() {
+; CHECK-LABEL: test_external:
+entry:
+; CHECK: ASM1: r3
+; CHECK-NOT:   r3
+; CHECK: bl    leaf_external
+; CHECK-NOT:   r3
+; CHECK: ASM2: r3
+  %0 = tail call i32 asm sideeffect "// ASM1: $0", "={r3},0"(i32 undef)
+  tail call void @leaf_external()
+  %1 = tail call i32 asm sideeffect "// ASM2: $0", "={r3},0"(i32 %0)
+  ret void
+}




More information about the llvm-commits mailing list