llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.11k stars 11.1k forks source link

missed optimization: rauw of a function with an identical one #21599

Open llvmbot opened 9 years ago

llvmbot commented 9 years ago
Bugzilla Link 21225
Version trunk
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @majnemer,@hfinkel,@yuanfang-chen

Extended Description

opt -O3 will not modify

declare void @​bar() define linkonce_odr void @​foo() unnamed_addr { call void @​bar() ret void } @​v = global void()* @​foo

but it could change it to

declare void @​bar() @​v = global void()* @​bar

llvmbot commented 9 years ago

I think Rafael is correct, any single global marked unnamed_addr does not care how its address compares to other globals. Thus you can merge it into another one that isn't unnamed_addr.

Mergefunc should be taught to do this, in the same sense that mergefunc should be taught to merge constants as well as functions. (Why do that? Consider the case that two functions are different because they refer to different vtables, and two vtables are different because the refer to different functions. But really you could merge the vtables and the functions. In this case, it would be smart for mergefunc to also do thunk removal as part of that folding, to permit more constant and function merging.)

llvmbot commented 9 years ago

Should @​bar be unnamed_addr as well?

I think the optimization is still valid. You only can't do it if both are not unnamed_addr if I remember the rules correctly.

991901f3-cc14-4404-b340-165691b62a58 commented 9 years ago

Should @​bar be unnamed_addr as well?