|
From: Nuno L. <nun...@sa...> - 2008-03-24 18:23:19
|
Hi, Today I've written a simple peephole optimizer that works after the instruction selection and before register allocation. So it takes an array of instructions and outputs another array of instructions. It's also independent of the platform. The patch is available at: http://web.ist.utl.pt/nuno.lopes/valgrind_vex_peephole_optimizations.txt Currently it only removes redudant MOVs between virtual registers that can be propagated forward. Imagine this: 9 movl %vr16,%vr85 ; %vr16 isn't referenced below this line 10 subl $0x4,%vr85 (maps %vr85 to %vr16) the movl is removed and translated into: 9 subl $0x4,%vr16 With only this simple transformation, I was able to reduce the number of instructions of a simple block (instrumented with memcheck) from 120 to 106, which is quite good. The number of register spills is also hugely reduced (on a x86 host)! (memcheck creates some unnecessary moves because of the dirty handler arguments). The caveats? Well it segfaults *after* compiling all the blocks, which is weird.. I get the following error: ==28498== Invalid read of size 1 ==28498== at 0x4015508: (within /lib/ld-2.6.1.so) ==28498== by 0x4013CB5: (within /lib/ld-2.6.1.so) ==28498== by 0x400134E: (within /lib/ld-2.6.1.so) ==28498== by 0x40009A6: (within /lib/ld-2.6.1.so) ==28498== Address 0x10090188 is not stack'd, malloc'd or (recently) free'd ==28498== ==28498== Process terminating with default action of signal 11 (SIGSEGV) ==28498== Access not within mapped region at address 0x10090188 ==28498== at 0x4015508: (within /lib/ld-2.6.1.so) ==28498== by 0x4013CB5: (within /lib/ld-2.6.1.so) ==28498== by 0x400134E: (within /lib/ld-2.6.1.so) ==28498== by 0x40009A6: (within /lib/ld-2.6.1.so) ==28498== If you believe this happened as a result of a stack overflow in your ==28498== program's main thread (unlikely but possible), you can try to increase ==28498== the size of the main thread stack using the --main-stacksize= flag. ==28498== The main thread stack size used in this run was 8388608. ==28498== ==28498== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0) ==28498== malloc/free: in use at exit: 0 bytes in 0 blocks. ==28498== malloc/free: 0 allocs, 0 frees, 0 bytes allocated. ==28498== For counts of detected errors, rerun with: -v ==28498== All heap blocks were freed -- no leaks are possible. ./vg-in-place: line 8: 28498 Segmentation fault VALGRIND_LIB=$d/.in_place VALGRIND_LIB_INNER=$d/.in_place $d/coregrind/valgrind "$@" Do you know what might be causing the problem? Also, after this is working correctly (i.e. fixing this segfault and running the tests), do you think this could be incorporated in valgrind/VEX? Regards, Nuno |