Open Quuxplusone opened 7 years ago
Bugzilla Link | PR33604 |
Status | NEW |
Importance | P enhancement |
Reported by | Davide Italiano (ditaliano@apple.com) |
Reported on | 2017-06-26 15:29:25 -0700 |
Last modified on | 2017-10-18 04:09:35 -0700 |
Version | trunk |
Hardware | PC All |
CC | charles.saternos@gmail.com, davidxl@google.com, joker.eph@gmail.com, llvm-bugs@lists.llvm.org, peter@pcc.me.uk, tejohnson@google.com, vivekvpandya@gmail.com |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
This problem could be phrased more generally as ThinLTO sumamry hasn't enough information to perform interprocedural constant propagation (both propagating constant values into arguments & return values), but solving the problem for return values should allow us to solve the problem for arguments with a similar solution.
What strikes me the most right now is that the regular LTO still has a call, why is that?
We should indeed. If the two functions are in the same TU we throw the function
away.
My wild guess is that we're somehow missing some attribute that allows us to
prove the call has no side effects and therefore can be removed.
https://godbolt.org/g/ctH7hT
I think this is an equally interesting but separate bug. I'll consider taking a
look in the next days.
So, that actually depends on what you pass as optimization level for the per-TU
pipeline.
Nothing:
$ ../clang a.c b.c -flto -fuse-ld=lld -Wl,-save-temps -o patatino-lto
$ ../llvm-dis patatino-lto.0.5.precodegen.bc -o -
; ModuleID = 'patatino-lto.0.5.precodegen.bc'
source_filename = "ld-temp.o"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: noinline nounwind optnone uwtable
define internal fastcc void @patatino() unnamed_addr #0 {
entry:
ret void
}
; Function Attrs: noinline nounwind optnone uwtable
define i32 @main() local_unnamed_addr #0 {
entry:
%retval = alloca i32, align 4
store i32 0, i32* %retval, align 4
call fastcc void @patatino()
ret i32 47
}
attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-
sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false"
"no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-
math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-
zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-
size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87"
"unsafe-fp-math"="false" "use-soft-float"="false" }
(this is because attribute #0 contains `optnone`).
with -O1:
$ ../clang -O1 a.c b.c -flto -fuse-ld=lld -Wl,-save-temps -o patatino-lto
$ ../llvm-dis patatino-lto.0.5.precodegen.bc -o -
; ModuleID = 'patatino-lto.0.5.precodegen.bc'
source_filename = "ld-temp.o"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: norecurse nounwind readnone uwtable
define i32 @main() local_unnamed_addr #0 {
entry:
ret i32 47
}
attributes #0 = { norecurse nounwind readnone uwtable "correctly-rounded-divide-
sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false"
"no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-
tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-
trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64"
"target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-
soft-float"="false" }