On Fri, 11 Mar 2005, Markus F.X.J. Oberhumer wrote:> Is there an optimization pass that eliminates redundant pointer
> arithmethics ? In the example below llvm is only able to optimize
> away the subtraction in test1, but not in test2/3.
Nope, there isn't anything yet. This should be handled by the instruction
combiner. I'll file an enhancement PR for this, and sometime when I have
a couple of spare cycles I'll implement it (unless someone beats me to it
:)
Thanks for noticing this!
-Chris
> #include <stddef.h>
>
> int test1(int a, int b) {
> int d = b - a;
> a = b - d; // no-op
> return a;
> }
>
> char* test2(char* a, char* b) {
> ptrdiff_t d = b - a;
> a = b - d; // no-op on all llvm-supported machines
> return a;
> }
>
> int test3(char* a, char* b, char* c) {
> ptrdiff_t d = b - a;
> return (d == 8) || ((a = b - d) < c); // a = ... is a no-op
> }
>
>
>
-Chris
--
http://nondot.org/sabre/
http://llvm.cs.uiuc.edu/