/* * libbinrec: a recompiling translator for machine code * Copyright (c) 2016 Andrew Church * * This software may be copied and redistributed under certain conditions; * see the file "COPYING" in the source code distribution for details. * NO WARRANTY is provided with this software. */ #include "src/rtl-internal.h" #include "tests/common.h" static unsigned int opt_flags = BINREC_OPT_DSE; static int add_rtl(RTLUnit *unit) { int reg1, reg2, reg3, reg4, reg5, reg6; EXPECT(reg1 = rtl_alloc_register(unit, RTLTYPE_ADDRESS)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_ARG, reg1, 0, 0, 0)); EXPECT(reg2 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_ARG, reg2, 0, 0, 1)); EXPECT(reg3 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_ARG, reg3, 0, 0, 2)); EXPECT(reg4 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_SELECT, reg4, reg2, reg3, reg1)); EXPECT(reg5 = rtl_alloc_register(unit, RTLTYPE_INT32)); /* If DSE improperly rolls back reg1/2/3 death at reg4, the registers * will appear to die at this instruction and thus be (incorrectly) * eliminated. */ EXPECT(rtl_add_insn(unit, RTLOP_SELECT, reg5, reg2, reg3, reg1)); EXPECT(reg6 = rtl_alloc_register(unit, RTLTYPE_INT32)); EXPECT(rtl_add_insn(unit, RTLOP_CMPXCHG, reg6, reg1, reg2, reg3)); return EXIT_SUCCESS; } static const char expected[] = #ifdef RTL_DEBUG_OPTIMIZE "[info] Dropping dead store to r4 at 3\n" "[info] Killing instruction 3\n" "[info] Dropping dead store to r5 at 4\n" "[info] Killing instruction 4\n" #endif " 0: LOAD_ARG r1, 0\n" " 1: LOAD_ARG r2, 1\n" " 2: LOAD_ARG r3, 2\n" " 3: NOP\n" " 4: NOP\n" " 5: CMPXCHG r6, (r1), r2, r3\n" "\n" "Block 0: --> [0,5] --> \n" ; #include "tests/rtl-optimize-test.i"