Bug 452 - memset/memcpy analysis/optimizations need improving
: memset/memcpy analysis/optimizations need improving
Status: RESOLVED FIXED
Product: libraries
Classification: Unclassified
Component: Interprocedural Optimizations
: trunk
: All All
: P enhancement
Assigned To: Unassigned LLVM Bugs
:
: code-quality
: 2058 1226 1952 2059
:
  Show dependency treegraph
 
Reported: 2004-10-20 12:46 CDT by Brian R. Gaeke
Modified: 2009-04-22 04:37 CDT (History)
2 users (show)

See Also:


Attachments
Edits a hard-coded string in an unrolled loop (752 bytes, text/x-c++src)
2007-04-05 16:57 CDT, Mathias Gaunard
Details
example with poor memcpy optimization (345 bytes, text/plain)
2008-01-28 23:55 CST, Duncan Sands
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Brian R. Gaeke 2004-10-20 12:46:06 CDT
Just so this doesn't get lost, I'm filing a "wishlist" item for this.

Date: Wed, 6 Oct 2004 14:25:30 -0500 (CDT)
From: Chris Lattner <sabre@nondot.org>
Subject: memset optimizations

memset currently inhibits multiple optimizations, e.g. memset/load doesn't
get copy-propagated, memset doesn't cause dead stores to die, and memset
inhibits SRA.  This should be fixed!

Also: memset(&X, 4) -> store int 0, X   iff X is aligned

Also, memset should not kill unaliased loads/stores.
Comment 1 Mathias Gaunard 2007-04-05 16:57:46 CDT
Created attachment 759 [details]
Edits a hard-coded string in an unrolled loop

I was told in the IRC channel that the non optimized LLVM code I was getting of
the attached C++ code was related to this issue.
It becomes optimized when the string 's' becomes small, like "this".
Comment 2 Chris Lattner 2007-04-08 19:57:19 CDT
Bug 1309 is also related to this.
Comment 3 Duncan Sands 2008-01-28 23:55:17 CST
Created attachment 1358 [details]
example with poor memcpy optimization

In the last line
        return r + x.A;
the value of x.A is zero, but LLVM doesn't understand this.
Presumably this is because it thinks memcpy has modified x,
even though it copies from x and not to it.
Comment 4 Chris Lattner 2008-01-28 23:58:15 CST
Bug 1952 is one specific optimization that we can do, relating it.
Comment 5 Owen Anderson 2008-04-09 03:27:16 CDT
This has gotten a lot better recently, with work Chris and I have done which is
now in the MemCpyOpt pass.  There's still a lot to do, though.
Comment 6 Owen Anderson 2009-04-22 04:37:27 CDT
I'm closing this open-ended bug, as we'll never catch EVERY case.  If you still
have specific cases that you'd like to see addressed, please file individual
PRs for them.