New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
poor optimization in presence of bitcast'ed pointer #2991
Comments
Please add the #if-ed out code in clang:test/CodeGen/2008-07-30-implicit-initialization.c back when fixed. |
Looks like something Owen might be interested in. |
GVN deliberately does not catch this case in order to improve compile time. We don't want to have to reason about the size of stores to make sure that the loads are completely contained within them. I don't anticipate GVN supporting this anytime in the near future. |
Okay. Its still a very straightforward optimization to change the writes through bitcasts to type safe stores in this particular case. Are you saying its not worth it or just that GVN shouldn't be the one to do it? |
Added another test case which should reduce to a constant. This case is coming from just a bitfield access not a memset. |
Here is another test case which produces really horrible --
|
Comment #8 is a different issue: lack of load merging in the code generator (turning two i16 loads into an i32 load when safe). The recent SROA improvements don't cover the original testcase because it is only setting two elements of the array not the entire thing. I've been pondering some more aggressive changes that could handle it, but I don't know when/if I'll ever get to them. |
With recent SROA improvements, the example in comment8 is optimized properly for X86-64, but we still get ugly code on x86-32. The issue is that llvm-gcc is passing the struct with 'byval' instead of as an i64 with x86-32, so there isn't much the optimizer can do (other than load merging in the code generator). |
clang has the same problem fwiw. The example in comment #6 is handle properly. |
The original example is also optimized now. I'm going to close this bug and file a follow-on for the remaining issue. |
I filed Bug 3473 with the remaining codegen issue. The SROA issue is fixed. |
mentioned in issue llvm/llvm-bugzilla-archive#3473 |
Extended Description
The attached test case (foo.ll) should optimize down to a constant return. I believe the presence of the bitcast is inhibiting further optimization though.
A relatively simple fix (I believe) would be to reduce the stores through a bitcasted pointer to separate stores into the proper type when obvious.
Alternatively, this code arises from a lowered memset, which could be changed to lower in a type specific way. The original .ll is also attached.
The text was updated successfully, but these errors were encountered: