LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 892 - [scalarrepl] Should be able to scalarrepl 'union's with pointers in them
Summary: [scalarrepl] Should be able to scalarrepl 'union's with pointers in them
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Scalar Optimizations (show other bugs)
Version: 1.0
Hardware: Macintosh MacOS X
: P enhancement
Assignee: Chris Lattner
URL:
Keywords: code-quality
Depends on:
Blocks:
 
Reported: 2006-08-30 01:17 PDT by Chris Lattner
Modified: 2010-02-22 12:54 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2006-08-30 01:17:35 PDT
Consider:
#include <cassert>
struct Val {
  int *A, B;
  Val() : A(0), B(2) {}
};
Val foo();
void bar(Val X, Val Y);

void test(Val Op) {
  bar(Op, foo());
}
on X86.

We currently generate really horrible code, because we are not able to eliminate any intermediate 'Val' 
objects.  We should do the right thing in three places, but don't do any of them:

1. llvm-gcc4 is lowering the 'pass struct by value' code into bad code that casts the address of the 
struct to a long*, then loads/stores the entire struct at once.  It doesn't need to do this.  In this specific 
case on X86, it can pass the two elements and get the same effect.
2. ScalarRepl doesn't understand the pointer cast in this case, because one element of the struct is a 
pointer (it handles {int,int} fine).
3. The code generator should handle this, because the 'long' load/stores gets split into 2x i32 loads, 
which should be forward prop'd.  However, because it's not using (even trivial) alias analysis, it doesn't 
get this.

We should fix this problem at all of these levels.

-Chris
Comment 1 Chris Lattner 2006-10-08 17:59:36 PDT
#3 is taken care of when Jim's CodeGen AA stuff is enabled.

-Chris
Comment 2 Chris Lattner 2006-10-08 18:54:20 PDT
Fixed, patches here:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20061002/038407.html
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20061002/038409.html

Testcase here:
Transforms/ScalarRepl/union-pointer.ll

-Chris