[llvm-dev] "Unusual" linkage inhibits interprocedural constant propagation?

Alex P. via llvm-dev llvm-dev at lists.llvm.org
Fri Oct 23 20:40:54 PDT 2020


Dear LLVM developers and adopters!

$ cat ipcp-1.ll
define
;linkonce_odr
dso_local i32 @f() noinline {
    ret i32 123
}
define dso_local i32 @g()
{
    %res = call i32 @f()
    ret i32 %res
}
$ opt-10 -S -ipconstprop ipcp-1.ll
; ModuleID = 'ipcp-1.ll'
source_filename = "ipcp-1.ll"

; Function Attrs: noinline
define dso_local i32 @f() #0 {
   ret i32 123
}

define dso_local i32 @g() {
   %res = call i32 @f()
   ret i32 123 <========== note the result
}

attributes #0 = { noinline }

BUT:

$ cat ipcp-2.ll
define
linkonce_odr
dso_local i32 @f() noinline {
    ret i32 123
}
define dso_local i32 @g()
{
    %res = call i32 @f()
    ret i32 %res
}
$ opt-10 -S -ipconstprop ipcp-2.ll
; ModuleID = 'ipcp-2.ll'
source_filename = "ipcp-2.ll"

; Function Attrs: noinline
define linkonce_odr dso_local i32 @f() #0 {
   ret i32 123
}

define dso_local i32 @g() {
   %res = call i32 @f()
   ret i32 %res <========== note the (lack of) result
}

attributes #0 = { noinline }

WHY? It this a bug?

I observe the same behavior if I replace "-ipconstprop" with "-O3" or 
replace "linkonce_odr" with "available_externally", and if I use an 
equivalent testcase in C++ (compiled with the clang++ frontend). No 
problem with "external", "private" or "hidden" linkages. Also note that 
those "linkonce_odr"/"available_externally" do not inhibit, e.g., 
inlining (if I remove "noinline"), that is, as implied from the IR 
documentation.

I am using LLVM version 10.0.0.

This is a showstopper for my project (actually trying to use LLVM as an 
affordable static type inferer for a dynamically typed PL).

Thanks for any help
-- 
Alex <alex at webprise.net>


More information about the llvm-dev mailing list